[SciPy-user] Problems with numpy.ndarray

Frank Zwaard fzwaard at gmail.com
Wed Nov 15 11:10:27 EST 2006


Hi

I am super-new to python.
I was trying the examples here:
http://www.scipy.org/Cookbook/Interpolation
but I get really strange graphics :((

Even with the first example (Interpolation of an N-D curve) I have problems:
all the points are plotted with a y value of 0!!!
I simplified the example as follows

from numpy import r_, sin
from scipy.signal import cspline1d, cspline1d_eval
from pylab import plot, show

x = r_[0:10]
y = sin(x)
plot(x, y, 'o')
show()

But I get the same problem, every data in plotted on the axis x=0 :(((
I checked the arrays x and y and they are:

>>> type(x)
<type 'numpy.ndarray'>
>>> type(y)
<type 'numpy.ndarray'>
>>> print x
[0 1 2 3 4 5 6 7 8 9]
>>> print y
[ 0.          0.84147098  0.90929743  0.14112001 -0.7568025  -0.95892427
 -0.2794155   0.6569866   0.98935825  0.41211849]

I tried also this example
t = arange(0, 2.0, 0.1)
y = sin(2*pi*t)
tck = interpolate.splrep(t, y, s=1)
tnew = arange(0, 2.0, 0.01)
ynew = interpolate.splev(tnew, tck, der=0)
plot(t, y, "o", tnew, ynew)
print type(t)
print type(y)
print type(tnew)
print type(ynew)

The plot t,y is perfect, while the plot tnew,ynew is a flat line :(
The only thing that I could see is that t,y,tnew are
<type 'array'>
while ynew is
<type 'numpy.ndarray'>
the same type as the first example.

Does anyone has any idea what could be the problem?

I am using  a Linux FC5 intel 32 bit machine, with the following
python related packages:
via RPM: rpm -qa|grep py
dbus-python-0.61-3
pycairo-1.0.2-1.2.1
gnome-python2-2.12.4-1
gnome-python2-gtkhtml2-2.14.0-1
python-urlgrabber-2.9.8-2
python-sqlite-1.1.7-1.2
audit-libs-python-1.1.5-1
gnome-python2-bonobo-2.12.4-1
python-devel-2.4.3-9.FC5
pytz-2005r-2.fc5
pyorbit-2.0.1-4.2.1
python-ldap-2.0.6-5.2.1
python-2.4.3-9.FC5
python-dateutil-1.1-2.fc5
python-imaging-1.1.5-5.fc5
rpm-python-4.4.2-15.2
python-elementtree-1.2.6-4.2.1
python-numeric-23.7-2.2.1
MySQL-python-1.2.0-3.2.2
gnome-python2-gtksourceview-2.14.0-1
gnome-python2-gnomevfs-2.12.4-1
pygtk2-libglade-2.8.6-0.fc5.1
libxml2-python-2.6.23-1.2
gnome-python2-desktop-2.14.0-1
gnome-python2-gnomeprint-2.14.0-1
pygtk2-devel-2.8.6-0.fc5.1
python-matplotlib-0.87.3-1.fc5
pyxf86config-0.3.24-1
libselinux-python-1.29.7-1.2
gnome-python2-canvas-2.12.4-1
gnome-python2-extras-2.14.0-1
pygtk2-2.8.6-0.fc5.1

Installed manually:

basemap-0.9.3.tar.gz
basemap-data-0.9.tar.gz
gnuplot-py-1.7.tar.gz
numpy-1.0.tar.gz
scipy-0.5.1.tar.gz

Thank you very much for any help that you can give me

Ciao

Frank



More information about the SciPy-User mailing list