[SciPy-User] SciPy-User Digest, Vol 91, Issue 21

Michael Hull mikehulluk at googlemail.com
Wed Mar 16 05:26:27 EDT 2011


> Message: 6
> Date: Tue, 15 Mar 2011 14:23:47 -0500
> From: Warren Weckesser <warren.weckesser at enthought.com>
> Subject: Re: [SciPy-User] 1 dimensional interpolation of vectors
> To: SciPy Users List <scipy-user at scipy.org>
> Message-ID:
>        <AANLkTinYC_P4aTtX6FsE1GZui6zGTzC318cjVJg-WWz4 at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> 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.

Ah, thats great, I'll give this a try.
Thanks

Mike



More information about the SciPy-User mailing list