[SciPy-Dev] Bug in use of np.sign() function with sparse csc_matrix?

Warren Weckesser warren.weckesser@enthought....
Sun Jan 22 11:52:13 CST 2012


In all the examples that I've tried with a sparse csc_matrix `a`, `sign(a)`
always returns 1.  I expect it to return the matrix of element-wise signs
of a.  For example:

In [1]: from scipy.sparse import csc_matrix

In [2]: a = csc_matrix([[0.0, 1.0, 2.0], [0.0, 0.0, -3.0], [0.0, 0.0, 0.0]])

In [3]: a.todense()
Out[3]:
matrix([[ 0.,  1.,  2.],
        [ 0.,  0., -3.],
        [ 0.,  0.,  0.]])

In [4]: np.sign(a.todense())
Out[4]:
matrix([[ 0.,  1.,  1.],
        [ 0.,  0., -1.],
        [ 0.,  0.,  0.]])

In [5]: np.sign(a)   # Incorrect result?
Out[5]: 1

In [6]: import scipy

In [7]: scipy.__version__
Out[7]: '0.11.0.dev-81dc505'

In [8]: np.__version__
Out[8]: '1.6.1'


I think that's a bug, but if someone knows better, let me know!

Warren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-dev/attachments/20120122/90932298/attachment.html 


More information about the SciPy-Dev mailing list