[SciPy-user] Cookbook: Interpolation of an N-D curve error

Angus McMorland a.mcmorland at auckland.ac.nz
Mon Jun 19 18:15:40 CDT 2006


Hi David et al,

Thanks for your interest.

David Huard wrote:
> Hi Angus,
> 
> I updated scipy and numpy this morning, and the example ran fine, 
> except for the import Float64 statement that has to be changed to 
> float64. 

Yep. I got that one okay - in fact neither declaration seems to be
required for the example to work now on my laptop. However, some problem
still remains - see below.

> You may want to turn pdb on in ipython and find out what 
> variable is triggering the exception. I'd like to help more but I 
> have no idea what is going on in your case. Did you modify the 
> example or ran it as is?
> 
> David
> 
> 2006/6/16, Angus McMorland <a.mcmorland at auckland.ac.nz 
> <mailto:a.mcmorland at auckland.ac.nz>>:
>
> I'm getting a TypeError when trying the N-D curve cookbook example (
>  http://www.scipy.org/Cookbook/Interpolation) with numpy 0.9.9.2630 
> and scipy 0.5.0.1979.
> 
> The error is:
> 
> In [158]: tckp,u = splprep([x,y,z],s=s,k=k,nest=-1)
> 
---------------------------------------------------------------------------
> 
> exceptions.TypeError                                 Traceback (most 
> recent call last)
> 
> [snip]<ipython console>
> 
> /usr/lib/python2.3/site-packages/scipy/interpolate/fitpack.py in 
> splprep(x, w, u, ub, ue, k, task, s, t, full_output, nest, per, 
> quiet) 215     iwrk=_parcur_cache['iwrk'] 216 
> t,c,o=_fitpack._parcur(ravel(transpose(x)),w,u,ub,ue,k,task,ipar,s,t,
>  --> 217                              nest,wrk,iwrk,per) 218 
> _parcur_cache['u']=o['u'] 219     _parcur_cache['ub']=o['ub']
> 
> TypeError: array cannot be safely cast to required type

After a bit more poking around, I've found that the routine runs fine on
my i686 debian laptop, but not on my amd64 desktop machine, both running
identical svn versions of numpy (0.9.9.2631) and scipy (0.5.0.1980) in
python2.3 (and python2.4 also works on the i686 machine).

I attach the script I ran - identical to the example in the cookbook
except for the removal of the Float64.

ipdb halts on line 22, then line 217 of fitpack.py in splprep. Using
ipdb to look at the variables shows me that w, u and s are somehow
ill-defined, but I don't know exactly what's going on. Here's the ipdb
session print-out:

ipdb> whatis w
<type 'numpy.ndarray'>
ipdb> w.shape
/home/amcmorl/tmp/spl.py
     20
     21 # find the knot points
---> 22 tckp,u = splprep([x,y,z],s=s,k=k,nest=-1)
     23
     24 # evaluate spline, including interpolated points

/usr/lib/python2.3/site-packages/scipy/interpolate/fitpack.py in splprep()
    215     iwrk=_parcur_cache['iwrk']
    216
t,c,o=_fitpack._parcur(ravel(transpose(x)),w,u,ub,ue,k,task,ipar,s,t,
--> 217                              nest,wrk,iwrk,per)
    218     _parcur_cache['u']=o['u']
    219     _parcur_cache['ub']=o['ub']

ipdb> whatis u
<type 'numpy.ndarray'>
ipdb> u.shape
/home/amcmorl/tmp/spl.py
     21 # find the knot points
---> 22 tckp,u = splprep([x,y,z],s=s,k=k,nest=-1)
     23

ipdb> whatis s
<type 'float'>
ipdb> s
WARNING: Failure executing file: <spl.py>

In [23]:

Requesting s kicks me out of the debugger altogether.

Other variables seem okay:

x: numpy.ndarray, shape = 3,100, dtype.type = <type 'float64scalar'>
ub: int, 0
ue: int, 1
k: int, 2
task: int, 0
ipar: bool, False
t: numpy.ndarray, array([], dtype=float64)
nest: int, 103
wrk: numpy.ndarray, array([], dtype=float64)
iwrk: numpy.ndarray, array([], dtype=int64)
per: int, 0

I hope that helps work out what's going on...

Angus.
-- 
Angus McMorland
email a.mcmorland at auckland.ac.nz
mobile +64-21-155-4906

PhD Student, Neurophysiology / Multiphoton & Confocal Imaging
Physiology, University of Auckland
phone +64-9-3737-599 x89707

Armourer, Auckland University Fencing
Secretary, Fencing North Inc.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: spl.py
Type: text/x-python
Size: 1059 bytes
Desc: not available
Url : http://www.scipy.net/pipermail/scipy-user/attachments/20060620/bafb97ee/spl.py


More information about the SciPy-user mailing list