[SciPy-dev] Possibly bug in sparse.py
Robert Cimrman
cimrman3 at ntc.zcu.cz
Tue Feb 14 06:01:55 EST 2006
Nils Wagner wrote:
> C =dot(A,XX)+dot(XX,B)
> File "/usr/local/lib/python2.4/site-packages/scipy/sparse/sparse.py",
> line 532, in __add__
> raise ValueError, "inconsistent shapes"
> ValueError: inconsistent shapes
>
>>>>A
>
> <317x317 sparse matrix of type '<type 'float64scalar'>'
> with 7327 stored elements (space for 7327)
> in COOrdinate format>
>
>>>>XX
>
> array([[0, 1, 1, ..., 1, 1, 1],
> [1, 0, 1, ..., 1, 1, 1],
> [1, 1, 0, ..., 1, 1, 1],
> ...,
> [1, 1, 1, ..., 1, 1, 1],
> [1, 1, 1, ..., 1, 1, 1],
> [1, 1, 1, ..., 1, 1, 1]])
>
>>>>shape(XX)
>
> (317, 10)
>
>>>>shape(B)
>
> (10, 10)
>
>
>>>>B
>
> <10x10 sparse matrix of type '<type 'float64scalar'>'
> with 28 stored elements (space for 28)
> in Compressed Sparse Column format>
>
> How can I fix this problem ?
First, use A * XX + XX * B instead of dot, since dot is a numpy.core
function and as such cannot handle sparse matrices.
Then there was a bug in the coo_matrix() constructor (not fixed yet in
svn, cannot log in...) causing that the shape was one less than the
actual shape... Thanks for debugging!
---
Side note, not directly related to your problem:
Another bug in the coo_matrix() constructor is that it does not work for
all value types (e.g. int32), because some dtypes are probably missing
in the type translation table of sparse.py - can someone (Travis? :)
help with this? I have followed the recent changes to the dtype object
only superficially...
r.
More information about the SciPy-Dev
mailing list