473,699 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

array type casting problem in scipy.interpola te

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.spl rep(x,y) function I get the following traceback

Traceback (most recent call last):
File "./optmat.py", line 138, in ?
initspline = interpol.getspl ine(initkeys,in ittable)
File "./optmat.py", line 77, in getspline
tck = interpolate.spl rep(self.x,self .y)
File "/usr/lib/python2.3/site-packages/scipy/interpolate/fitpack.py",
line 339, in splrep
t,c,o = _fitpack._curfi t(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.41566910377 401, 300.93263033980 6, 310.73745288220 601,
320.37272273901 8, 331.50867299465 199, 342.49791077348 101,
354.24069628571 402, 367.90576765578 601, 381.48998061538 498,
397.38539647435 903, 413.28081233333 302, 430.50084618055 598,
452.49723978102 196, 471.42297984790 901, 495.93697480000 003,
520.94220042016 798, 548.60284823008 897, 582.08565117370 904,
616.83703333333 301, 659.49065797872 311, 704.45593011363 599,
756.00148597561 008, 821.08770662251 698]

y:

[(1.49+1.8779999 999999999j), (1.53+1.889j), (1.53+1.893j),
(1.54+1.8979999 999999999j), (1.48+1.883j), (1.48+1.871j),
(1.5+1.86600000 00000001j), (1.48+1.895j), (1.46+1.9330000 000000001j),
(1.47+1.952j), (1.46+1.958j), (1.45+1.948j),
(1.379999999999 9999+1.91399999 99999999j), (1.310000000000 0001+1.849j),
(1.04+1.833j), (0.62+2.081j), (0.429999999999 99999+2.4550000 000000001j),
(0.289999999999 99998+2.863j), (0.209999999999 99999+3.2719999 999999998j),
(0.140000000000 00001+3.6970000 000000001j), (0.13+4.1029999 999999998j),
(0.140000000000 00001+4.5119999 999999996j), (0.16+5.0830000 000000002j)]

I would really appreciate some help.

Thanks,

Alex
Jul 19 '05 #1
2 3841
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
3763
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 you can delete a derived-class object via a base-class pointer...So, the correct destructor(s) gets invoked(the derived class one in particular) and the correct amount of memory is also released. But if the above is true, why isnt it a good...
11
4462
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 accomplish. // - - - - - - - - begin code - - - - - - - typedef int sm_t; typedef int bg_t; sm_t sm; bg_t bg;
204
13018
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 = {0,1,2,4,9};
1
1441
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 NXM, and then populate the elements of the objects. thanks for any help. Scott
8
1651
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
21101
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 to do this?
15
8436
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 a={int,float,char,int*..............................}, so that a should return me int and a should return me
3
2182
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 I've made a mask array for it, sources (stars/galaxies/etc.) are flagged with 1, sky is 0. Now I want to blow up the size of each flagged source by a factor of 2, or close to it. Meaning, if I originally have array(, ,
14
1765
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
8687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9174
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8914
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8884
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.