[SciPy-User] 1 dimensional interpolation of vectors

Warren Weckesser warren.weckesser at enthought.com
Tue Mar 15 15:23:47 EDT 2011


On Tue, Mar 15, 2011 at 1:33 PM, Michael Hull <mikehulluk at googlemail.com>wrote:

> Hi,
> Sorry for the confusing title!
> Firstly, thanks for all the great work on numpy and scipy, its very
> appreciated.
>
> What I have is an array of time recordings of various properties. If
> have recordings of prop1,prop2,prop3,prop4.... propN, and for each
> recording, I have the values at millisecond time intervals, stored in
> a 2 dimensional array.
> The properties are not linked, what I am trying to do is to find the
> value at say t=2.4ms, i.e.  a non integer millisecond, by linearly
> interpolating between the two time points 2ms and 3ms.
>
> I can do this in one dimension using scipy.interpolate.interp1d for
> each property, but what I would like to do is get an entire row in one
> go,, because the number of properties is
> pretty large.
>
> I can write this myself, but I was wondering if there was already
> something built in?
>
>

interp1d can take a 2D array for the y value.  For example,


In [16]: x = array([0.0, 1.0, 2.0, 3.0])

In [17]: y = array([[1.0, 0.0, 0.5, 10.5],[-4, 2, 2, 0]])

In [18]: func = interp1d(x, y)

In [19]: func(0.5)
Out[19]: array([ 0.5, -1. ])

In [20]: func(1.1)
Out[20]: array([ 0.05,  2.  ])

In [21]: func(2.75)
Out[21]: array([ 8. ,  0.5])


So if you have a 2D array of measurements--one row for each "prop"--you can
use interp1d without a loop.  If each property is a column, you can use the
'axis=0' keyword argument in interp1d, or transpose the array.

Warren





> Many thanks
>
>
> Mike
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110315/cc488e1b/attachment.html>


More information about the SciPy-User mailing list