Skip to content Skip to sidebar Skip to footer

How To Extend An Array With Linear Interpolation

What I want is to extend an array of length m to an array of length n (n>m), and interpolate the missing values linearly. For example, I want to extend this array [1,5,1,7] to a

Solution 1:

The interp function from numpy can do what you want.

Example:

>>>xp = [1, 2, 3]>>>fp = [3, 2, 0]>>>np.interp(2.5, xp, fp)
1.0
>>>np.interp([0, 1, 1.5, 2.72, 3.14], xp, fp)
array([ 3. ,  3. ,  2.5 ,  0.56,  0. ])

Post a Comment for "How To Extend An Array With Linear Interpolation"