473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 3819
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: amparikh | last post by:
Ok, my question is not about Virtual destructors and why, but more on the significance. Generally we have a virtual destructor in the base class ( and inadvertently in the derived class) so that...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
1
by: Stormslayer | last post by:
Folks: How do you create a multidimesional array of objects w/ the size of the array entered at runtime? So basically, for an arbitrary class, create an array and then *.resize it to be of size...
8
by: SpreadTooThin | last post by:
Basically I think the problem is in converting from a 32 bit integer to a 16 bit integer. I have two arrays: import array a = array.array('L', ) b = array.array('H', ) b = a
8
by: SpreadTooThin | last post by:
import array a = array.array('f', ) print a.mean() print a.std_dev() Is there a way to calculate the mean and standard deviation on array data? Do I need to import it into a Numeric Array...
15
by: Madhur | last post by:
Hi All, I would like you help me in creating an array of data types. I am interested in look at the the data type which looks like this Array...
3
by: eso40043 | last post by:
Hi guys, I've asked for help here once before with great results, I thought I'd try it again. (I'm on Ubuntu 6.06 with python 2.4. Xemacs as editor.) I have an image as a scipy array and...
14
by: KK | last post by:
Dear All I have a small problem with using as operator on value type array. Here is an example what I am trying to do. using System; using System.Collections.Generic; using System.Text;
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.