[SciPy-user] transition problems Numeric 24.1 and Numpy(=scipy core)

Hans Fangohr H.FANGOHR at soton.ac.uk
Tue Jan 10 11:19:23 EST 2006


Hi,

I noticed a problem with the newish scipy 0.4.3.1490 (scipy core: 0.8.4)
interacting with Numeric 24.1 (on a fink install of python2.4) even
though I have read before that it is believed this should work for
Numerix version >=24.

I summarise what I think the problem is, attach the source code and
list the error message below:

The program calls
y = scipy.integrate.odeint(rhs_function, y0, t)
where y0 is a Numeric array.

The type of the return object y is now a scipy.ndarray. In earlier
versions of scipy (for example 0.3.3_303.4573) the returned object was of
type (Numeric) array.

Subsequently, the code wants to manipulate y using Numeric functions such
as 'Numeric.concatenate' which fails. However, I thought this should work.
Any suggestions?


Finally, I'd like to add some explanation: I am well aware that this
example will work by using only scipy's ndarray, and I can also make this
work by converting the returned value y (from odeint) into a Numeric
array. However, this code is a shortened version from teaching materials
which (historically) are based on Numeric, and later scipy is introduced
to provide, for example, odeint. This all works with the oldish versions
of Numeric and scipy we have installed. It would be a great relief to know
that the code will still work for the students if our python software is
upgraded (or if they install a newer version at home).

I have attached the source code of the problematic program and list the
error messages below.

Looking forward to receiving any advice,

Hans



Error messages and standard output:


jarjar:~/tmp fangohr$ python2.4  ode1.py
Failed to import fftpack
No module named fftpack
Failed to import signal
No module named fftpack
Numeric version: 24.1
scipy version: 0.4.3.1490
scipy core version: 0.8.4
<type 'array'> <type 'scipy.ndarray'>
Traceback (most recent call last):
  File "ode1.py", line 18, in rhs
    dydt = N.concatenate( [dvdt,drdt] )   #this fails
  File "/sw/lib/python2.4/site-packages/Numeric/Numeric.py", line 236, in
concatenate
    return multiarray.concatenate(a)
ValueError: Invalid type for array
odepack.error: Error occured while calling the Python function named rhs
<type 'array'> <type 'scipy.ndarray'>
Traceback (most recent call last):
  File "ode1.py", line 18, in rhs
    dydt = N.concatenate( [dvdt,drdt] )   #this fails
  File "/sw/lib/python2.4/site-packages/Numeric/Numeric.py", line 236, in
concatenate
    return multiarray.concatenate(a)
ValueError: Invalid type for array
odepack.error: Error occured while calling the Python function named rhs
coming back from scipy's oddeint <type 'scipy.ndarray'>
position r = (  0.000000,   5.000000,   0.000000)
jarjar:~/tmp fangohr$




-------------- next part --------------
import Numeric as N
import scipy

def rhs( y, t ):
    v = y[0:3]
    r = y[3:6]

    mass = 1.0    #kg
    g = 9.81      #N/kg

    F_grav = N.array([0,-g, 0])

    dvdt = F_grav/mass       #this is a Numeric array
    drdt = v                 #this is a scipy.array

    print type(dvdt),type(drdt)

    dydt = N.concatenate( [dvdt,drdt] )   #this fails

    return dydt 


#just for the record
print "Numeric version:",N.__version__
print "scipy version:",scipy.__scipy_version__
print "scipy core version:",scipy.__core_version__


r = N.array([0,5,0])  #creation of initial values
v = N.array([0,0,0])

t = 0  
dt = 1/30.0
n = 1       #number of time steps
for i in range(n):
    y = N.concatenate((v,r))  #combine v and r into state vector y
    y = scipy.integrate.odeint( rhs, y, N.array([t,t+dt]) )
    print "coming back from scipy's oddeint",type(y)
    t = t + dt
    v = y[-1,0:3]
    r = y[-1,3:6]
    if r[1] < 0:         #if below base plate
        v[1] = -v[1]     #then reverse velocity (elastic bounce)
    print "position r = (%10f, %10f, %10f)" % (r[0],r[1],r[2]) 
    
    

    
    


More information about the SciPy-User mailing list