A
Alex
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,iwrk,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
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,iwrk,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