[SciPy-user] Trouble with arrays of arrays

Nicholas Kottenstette nkottens at nd.edu
Fri Jan 19 23:08:52 CST 2007


Hey All,

I was trying to write some code to handle polynomial matrices.
I want a matrix in which each entry is a reference to a possibly 
different length array
describing the i,jth polynomial.

For simplicity I want to represent the following 2x2 matrix
[2s+3, s+2;
3.3s+4.3, 1.2s+6.3]

M = array(
In [75]: N = 
array([[array([2.0,3.0]),array([1.0,2.0])],[array([3.3,4.3]),array([1.2,6.3])]],dtype=object_) 


In [76]: N
Out[76]:
array([[[2.0, 3.0],
       [1.0, 2.0]],

      [[3.3, 4.3],
       [1.2, 6.3]]], dtype=object)

In [77]: N.shape
Out[77]: (2, 2, 2)

Clearly this is not what I wanted to happen, I was expecting a 2x2 array 
with references to each object array.
If I modify my declaration of N slightly so that not all the arrays 
"fit" I can hack this to get what I want to see:

In [78]: N = 
array([[array([2.0,3.0]),array([1.0,2.0])],[array([3.3,4.3]),array([0.0,1.2,6.3])]],dtype=object_) 


In [79]: N
Out[79]:
array([[[ 2.  3.], [ 1.  2.]],
      [[ 3.3  4.3], [ 0.   1.2  6.3]]], dtype=object)

since 0s2+1.2s+6.3 = 1.2s+6.3

any suggestions to handle this problem differently are welcome.

Sincerely,

Nicholas


More information about the SciPy-user mailing list