469,915 Members | 2,697 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,915 developers. It's quick & easy.

array type casting problem in scipy.interpolate

Hi,

I need to perform cubic spline interpolation of a dataset. I am using
scipy. When I pass two arrays (x,y) to the
interpolate.splrep(x,y) function I get the following traceback

Traceback (most recent call last):
File "./optmat.py", line 138, in ?
initspline = interpol.getspline(initkeys,inittable)
File "./optmat.py", line 77, in getspline
tck = interpolate.splrep(self.x,self.y)
File "/usr/lib/python2.3/site-packages/scipy/interpolate/fitpack.py",
line 339, in splrep
t,c,o = _fitpack._curfit(x,y,w,xb,xe,k,task,s,t,nest,wrk,i wrk,per)
TypeError: Array can not be safely cast to required type

My understanding is that this problem arises because the "y" array
contains complex numbers and the splrep is trying to cast both arrays to
the same type. Is there a way around this? My data looks like this:

x:

[292.41566910377401, 300.932630339806, 310.73745288220601,
320.372722739018, 331.50867299465199, 342.49791077348101,
354.24069628571402, 367.90576765578601, 381.48998061538498,
397.38539647435903, 413.28081233333302, 430.50084618055598,
452.49723978102196, 471.42297984790901, 495.93697480000003,
520.94220042016798, 548.60284823008897, 582.08565117370904,
616.83703333333301, 659.49065797872311, 704.45593011363599,
756.00148597561008, 821.08770662251698]

y:

[(1.49+1.8779999999999999j), (1.53+1.889j), (1.53+1.893j),
(1.54+1.8979999999999999j), (1.48+1.883j), (1.48+1.871j),
(1.5+1.8660000000000001j), (1.48+1.895j), (1.46+1.9330000000000001j),
(1.47+1.952j), (1.46+1.958j), (1.45+1.948j),
(1.3799999999999999+1.9139999999999999j), (1.3100000000000001+1.849j),
(1.04+1.833j), (0.62+2.081j), (0.42999999999999999+2.4550000000000001j),
(0.28999999999999998+2.863j), (0.20999999999999999+3.2719999999999998j),
(0.14000000000000001+3.6970000000000001j), (0.13+4.1029999999999998j),
(0.14000000000000001+4.5119999999999996j), (0.16+5.0830000000000002j)]

I would really appreciate some help.

Thanks,

Alex
Jul 19 '05 #1
2 3688
bgs
The routine requires real arrays, and you are giving it one complex
one. It does not know what to do with the complex array. What are you
expecting it to do? If you need the real and imaginary parts to be
separately interpolated, then split the complex array into two real
arrays and use the routine twice.

Jul 19 '05 #2
On 30 Apr 2005 12:32:31 -0700, bgs <bg****@hotmail.com> said:
The routine requires real arrays, and you are giving it one complex
one. It does not know what to do with the complex array. What are you
expecting it to do? If you need the real and imaginary parts to be
separately interpolated, then split the complex array into two real
arrays and use the routine twice.


Hello,

Thanks for the pointer. I will interpolate the real and imaginary parts
separately then.

Regards,

Alex
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by amparikh | last post: by
204 posts views Thread by Alexei A. Frounze | last post: by
1 post views Thread by Stormslayer | last post: by
8 posts views Thread by SpreadTooThin | last post: by
8 posts views Thread by SpreadTooThin | last post: by
15 posts views Thread by Madhur | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.