Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sparse.as_coo does not work for N-by-1 np.matrix #199

gongliyu opened this issue Oct 16, 2018 · 1 comment

sparse.as_coo does not work for N-by-1 np.matrix #199

gongliyu opened this issue Oct 16, 2018 · 1 comment


Copy link

@gongliyu gongliyu commented Oct 16, 2018

When input a N-by-1 matrix of type np.matrix, sparse.as_coo throws an error. It correctly dispatchs to sparse.COO.from_numpy but can not handle it. Please see the following

In [1]: import scipy.sparse,sparse

In [2]: sp = scipy.sparse.random(10,1,0.5)

In [3]: mat = sp.argmax(1)

In [4]: sparse.as_coo(mat)
ValueError                                Traceback (most recent call last)
<ipython-input-4-5492fc8fff45> in <module>()
----> 1 sparse.as_coo(mat)

C:\Users\Liyu\Anaconda3\lib\site-packages\sparse\coo\ in as_coo(x, shape, fill_value)
   1750     if isinstance(x, np.ndarray):
-> 1751         return COO.from_numpy(x, fill_value=fill_value)
   1753     if isinstance(x, scipy.sparse.spmatrix):

C:\Users\Liyu\Anaconda3\lib\site-packages\sparse\coo\ in from_numpy(cls, x, fill_value)
    308             data = np.array(x, ndmin=1)
    309         return cls(coords, data, shape=x.shape, has_duplicates=False,
--> 310                    sorted=True, fill_value=fill_value)
    312     def todense(self):

C:\Users\Liyu\Anaconda3\lib\site-packages\sparse\coo\ in __init__(self, coords, data, shape, has_duplicates, sorted, cache, fill_value)
    223                 msg = ('The data length does not match the coordinates '
    224                        'given.\nlen(data) = {}, but {} coords specified.')
--> 225                 raise ValueError(msg.format(len(data), self.coords.shape[1]))
    226             if len(self.shape) != self.coords.shape[0]:
    227                 msg = ("Shape specified by `shape` doesn't match the "

ValueError: The data length does not match the coordinates given.
len(data) = 1, but 0 coords specified.
Copy link

@hameerabbasi hameerabbasi commented Oct 16, 2018

This is now fixed and tested in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants