[SciPy-user] Coo_constructor

Nils Wagner nwagner at iam.uni-stuttgart.de
Fri Dec 14 14:04:39 EST 2007


Hi all,

I use the coo constructor to build sparse matrices.
A_i = coo_matrix( (vals_i, (rows_i, cols_i)) )

I read the data for each matrix from a different file.

One of the matrices is rank-one with only non-zero entry.

(7, 7)        5.0

Another matrix has the entries

   (0, 0)        80000000.0
   (0, 1)        -120000000.0
   (1, 0)        -120000000.0
   (1, 1)        480000000.0
   (0, 2)        40000000.0
   (2, 0)        40000000.0
   (2, 2)        160000000.0
   (1, 3)        -240000000.0
   (3, 1)        -240000000.0
   (2, 3)        -120000000.0
   (3, 2)        -120000000.0
   (3, 3)        480000000.0
   (1, 4)        120000000.0
   (4, 1)        120000000.0
   (2, 4)        40000000.0
   (4, 2)        40000000.0
   (4, 4)        160000000.0
   (3, 5)        -240000000.0
   (5, 3)        -240000000.0
   (4, 5)        -120000000.0
   (5, 4)        -120000000.0
   (5, 5)        480000000.0
   (3, 6)        120000000.0
   (6, 3)        120000000.0
   (4, 6)        40000000.0
   :     :
   (9, 11)       -240000000.0
   (11, 9)       -240000000.0
   (10, 11)      -120000000.0
   (11, 10)      -120000000.0
   (11, 11)      480000000.0
   (9, 12)       120000000.0
   (12, 9)       120000000.0
   (10, 12)      40000000.0
   (12, 10)      40000000.0
   (12, 12)      160000000.0
   (11, 13)      -240000000.0
   (13, 11)      -240000000.0
   (12, 13)      -120000000.0
   (13, 12)      -120000000.0
   (13, 13)      480000000.0
   (11, 14)      120000000.0
   (14, 11)      120000000.0
   (12, 14)      40000000.0
   (14, 12)      40000000.0
   (14, 14)      160000000.0
   (13, 15)      120000000.0
   (15, 13)      120000000.0
   (14, 15)      40000000.0
   (15, 14)      40000000.0
   (15, 15)      80000000.0


How can I circumvent the
ValueError: shape mismatch: objects cannot be broadcast to 
a single shape

if I try to add the matrices ?

Nils





More information about the SciPy-User mailing list