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

Allow use of ellipsis in scipy.sparse slicing #2721

Closed
jnothman opened this issue Aug 13, 2013 · 4 comments · Fixed by #2759
Closed

Allow use of ellipsis in scipy.sparse slicing #2721

jnothman opened this issue Aug 13, 2013 · 4 comments · Fixed by #2759
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.sparse
Milestone

Comments

@jnothman
Copy link
Contributor

It should be legal to use an Ellipsis to slice sparse matrices so that they may be used alongside ndarrays.

>>> import numpy as np
>>> m = np.matrix([[0,1], [2,3]])
>>> import scipy.sparse as sp
>>> s = sp.csr_matrix(m)
>>> m[..., 1]
matrix([[1],
        [3]])
>>> s[..., 1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/sparse/csr.py", line 249, in __getitem__
    P = extractor(row, self.shape[0])        #[[1,2],j] or [[1,2],1:2]
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/sparse/csr.py", line 209, in extractor
    indices = asindices(indices)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/sparse/csr.py", line 191, in asindices
    raise IndexError('invalid index')
IndexError: invalid index
@cowlicks
Copy link
Contributor

There is currently a PR here for fancy indexing in Sparse matrices. I'll look into it asap.

@cowlicks
Copy link
Contributor

So... Since sparse matrices are limited to 2D, the Ellipsis is exactly the same as a :?

@jnothman
Copy link
Contributor Author

Yes. It's an uninteresting case, but compatibility is required.

@pv
Copy link
Member

pv commented Aug 13, 2013

Same as :, except that x[:,:,...] and x[:,...,:], x[...,:,:] are also allowed for 2D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.sparse
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants