[SciPy-user] Question w.r.t. sparse matrices

Nils Wagner nwagner at mecha.uni-stuttgart.de
Mon Mar 6 09:53:46 CST 2006


Nils Wagner wrote:
> Hi,
>
> Consider the sparse vector
>  >>> x
> <420x1 sparse matrix of type '<type 'float64scalar'>'
>         with 2 stored elements (space for 2)
>         in Compressed Sparse Row format>
>  >>> print x
>   (3, 0)        1.0
>   (30, 0)       1.0
>
> x.getnnz() yields the number of nonzero elements
>  >>> x.getnnz()
> 2
>
> How can I obtain the pattern of x ?
> I mean the indices of nonzero elements.
>
> Nils
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user
>   
Sorry for replying to myself. It seems to be not implemented yet.
 >>> where (x <>0)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/site-packages/scipy/sparse/sparse.py", line 
160, in __cmp__
    raise TypeError, "comparison of sparse matrices not implemented"
TypeError: comparison of sparse matrices not implemented

Nils



More information about the SciPy-user mailing list