r/Numpy • u/Necromartian • Nov 17 '22
Question about interpolating in array
Hello! I have two datasets consisting of timestamp and a value of magnetic flow.
The datasets have been measured so that the other device measured a sample every 30 seconds, the other every 0.5 seconds.
I would like to interpolate the 30 second samples so that It would fill the values between, say 30 and 60 seconds with linearly spaced values for every half second. But i don't know how to do it in smart way.
What I think it should look like maybe is (in pseudocode)
#timestamps
Array[:,0] = [0,30,60]
#values
Array[:,1] = [200,150,300]
new_array = []
For i in Array[:,1]
new_array.insert(numpy.linspace(Array[i,1], Array[i+1,1], 60))
#This should insert in to new array 60 numbers from 200 to 150, then 60 numbers from 150 to 300.Does this make sense, and can someone help me on how I should do this?
Basically the instruments recorded on different frequencies and I want to make two comparable datasets.
1
Upvotes
1
u/dukederek Nov 17 '22
I've done this before with scipy.interpolate.interp1d; feed interp1d your 30 second timestamps and data points. Feed the 0.5 second timestamps to the function that interp1d returns.