[SciPy-user] newscipy interp1d

Darren Dale dd55 at cornell.edu
Sat Dec 10 12:53:24 CST 2005


On Saturday 10 December 2005 1:38 pm, Christian Kristukat wrote:
> Hi,
> I get errors when using scipy.interpolate.interp1d from newscipy like the
> following:
>
> x=linspace(-1,4,20)
> y=x**2
> ip=interp1e(x,y)
> xn=linspace(-.5,1,200)
> yn=ip(xn)
>
> Traceback (most recent call last):
>    File "<stdin>", line 1, in ?
>    File
> "/usr/lib/python2.4/site-packages/scipy/interpolate/interpolate.py", line
> 180, in __call__
>      putmask(y_new, new_out.ravel(), self.fill_value)
>    File "/usr/lib/python2.4/site-packages/scipy/base/oldnumeric.py", line
> 187, in putmask
>      return a.putmask(v, mask)
> TypeError: array cannot be safely cast to required type
>
> I guess this a bug.?

This may be a casting problem. I'm not sure of the origin, but I have traced 
it as far back as the putmask method of the ndarray object:

from scipy import *

a=arange(10)
a.putmask(0,ones(10,'?')) # works
ones(10).astype('?') # works
a.putmask(0,ones(10)) # doesnt work

My hack for getting interp1d to work (until the actual issue is resolved) is 
to change line 179 in scipy/Lib/interpolate/interpolate.py from

new_out = ones(new_shape)*out_of_bounds

to 

new_out = ones(new_shape, '?')*out_of_bounds


Darren



More information about the SciPy-user mailing list