Matlab's spline equivalent in Python, three inputs.

前端 未结 2 719
野的像风
野的像风 2021-01-23 23:29

I\'m converting a matlab script to python and I have it a roadblock. In order to use cubic spline interpolation on a signal. The script uses the command spline with three input

2条回答
  •  爱一瞬间的悲伤
    2021-01-23 23:48

    Have you tried the InterpolatedUnivariateSpline within scipy.interpolate? If I understand the MatLab part correctly, then I think this will work.

    import numpy as np
    from scipy.interpolate import InterpolatedUnivariateSpline as ius
    
    a = [1,2,3,4,5,6]
    b = [r * 2 for r in a]
    c = ius(a, b, k=1)
    
    # what values do you want to query?
    targets = [3.4, 2.789]
    
    interpolated_values = c(targets)
    

    It seems this may add one more step to your code than what MatLab provides, but I think it is what you want.

提交回复
热议问题