[SciPy-Dev] Bug in use of np.sign() function with sparse csc_matrix?
Nils Wagner
nwagner@iam.uni-stuttgart...
Sun Jan 22 12:24:00 CST 2012
On Sun, 22 Jan 2012 11:52:13 -0600
Warren Weckesser <warren.weckesser@enthought.com> wrote:
> 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
>>> from scipy.linalg import signm
>>> signm(a.todense())
array([[ 1.00000000e+00, -2.01948392e-28,
-1.80945759e-25],
[ 0.00000000e+00, 1.00000000e+00,
7.06819371e-28],
[ 0.00000000e+00, 0.00000000e+00,
1.00000000e+00]])
Nils
More information about the SciPy-Dev
mailing list