Pseudo-implementation of "resolving" a table of values
I have a measurement array with 16,000 records in the form
[t] [value]
the problem is my datalogger is too slow and I only have units of measure every second. For my simulation I need the pseudo resolution to increase. Thus, each time step is divisible by 1000, and each measured value must be copied 1000 times. (see figure for clarity). So I increase the resolution of my measurement file.
How to do it efficiently (!!!) in Python
using numpy
. I don't want to iterate when creating an array of 16,000,000 records.
The trivial answer of simply dividing my temporary array by 1000 is not applicable in this case.
Edit: To make things even more complicated: except that in my image the time delta is NOT equidistant for every time time.
While it is difficult for you to tell exactly what you are asking for, I am assuming that you just want to interpolate between the values you already have. The good thing numpy
has a simple module built in to do this interp1d
( docs ):
>>> from scipy import interpolate
>>> x = np.arange(0, 10)
>>> y = np.exp(-x / 3.0)
>>> f = interpolate.interp1d(x, y)
>>> x_new = np.array([1.5, 2.5, 3.5])
>>> f(x_new)
array([ 0.61497421, 0.44064828, 0.31573829])
As for the second part of your question, numpy
again has a great built in for you! The function np.repeat
should do exactly what you are looking for, right down to the time variable step. The docs can be found here . See example below:
>>> values = np.array([1, 2, 3, 4])
>>> np.repeat(values, [2, 1, 2, 1])
array([1, 1, 2, 3, 3, 4])