[SciPy-dev] Arrays and matrices share memory?

Stephen Walton stephen.walton at csun.edu
Wed Oct 19 11:21:27 CDT 2005

I began tracking down the failures in scipy.test (full new install) this 
morning on the bus and hit two problems right off, both in expm3.  The 
first is easy to fix:  line 84 needs to change from

    eA = eye(*A.shape,**{'typecode':t})

    eA = eye(*A.shape,**{'dtype':t})

The second one is more subtle and here's a brief demonstration of the 

In [1]:import scipy as S

In [2]:A=S.array([[1.,1],[1,1]])

In [3]:trm = S.mat(A)

In [4]:trm
matrix([[ 1.,  1.],
       [ 1.,  1.]])

In [5]:A
array([[ 1.,  1.],
       [ 1.,  1.]])

In [6]:trm is A

In [7]:trm *= 0

In [8]:trm
matrix([[ 0.,  0.],
       [ 0.,  0.]])

In [9]:A
array([[ 0.,  0.],
       [ 0.,  0.]])

Notice that A has been set to zeros even though "trm is A" returns 
False.  My guess, without delving deeply into the code, is that in 
newcore A and trm are sharing the same array object.  expm3 (and 
probably many other routines in scipy) depend on B=mat(A) creating a 
completely new copy of A.  Should this be changed?

More information about the Scipy-dev mailing list