[Scipy-tickets] [SciPy] #1386: nonzero return types

SciPy Trac scipy-tickets@scipy....
Wed Feb 16 10:39:29 CST 2011

#1386: nonzero return types
 Reporter:  davidabarrett   |       Owner:  wnbell
     Type:  review          |      Status:  new   
 Priority:  normal          |   Milestone:  0.9.0 
Component:  scipy.sparse    |     Version:  0.8.0 
 Keywords:  nonzero result  |  
 The nonzero() method on an array returns arrays,
 on np.matrix returns matrices, but for sparse matrices
 returns arrays again.

 It wasn't obvious to me what type non-zero should return, but
 I had to write special-case code to deal with each of the three
 distinct types (using shape).

 I guess I was expecting to always get back arrays.  Barring that,
 I expected sparse matrices to return values consistently as matrices, but
 its not clear that a derived computation that returns *indices* should
 return a matrix.

 If the current behavior is the desired one, some additional documentation
 looks in order.   On a related note, I was unable
 to quickly find a type-independent way to iterate through the
 non-zero elements of an array, matrix, or sparse matrix.  Examples
 would be quite helpful here.

Ticket URL: <http://projects.scipy.org/scipy/ticket/1386>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.

More information about the Scipy-tickets mailing list