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

Nils Wagner nwagner at mecha.uni-stuttgart.de
Mon Mar 6 08:38:18 CST 2006


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




More information about the SciPy-user mailing list