FIX make __iter__ consistent between sparse arrays and matrices#19220
FIX make __iter__ consistent between sparse arrays and matrices#19220glemaitre wants to merge 3 commits intoscipy:mainfrom
Conversation
|
The message is quite explicit that this has not yet been implemented yet (maybe for a good reason of maybe not wanting to implement this in a general because of the ambiguity as whether to return a dense or sparse array as result). In scikit-learn we can probably always use the explicit indexing suggested in the message: |
Indeed, I missed the point of the 1D specification. I assume that I got sidetrack by the current behaviour of the In [8]: X = sparse.csr_array([[1, 2], [0, 3], [4, 0]])
In [9]: for row in X:
...: print(type(row))
...:
<class 'scipy.sparse._csr.csr_array'>
<class 'scipy.sparse._csr.csr_array'>
<class 'scipy.sparse._csr.csr_array'>
In [10]: for row in X:
...: print(row.shape)
...:
(1, 2)
(1, 2)
(1, 2)I would also expect a |
|
Yeah, this is a tough one. Since we're pretty close to having a 1-d COO format in #18530, I think I'd rather wait until we can return a proper 1d sparse row. |
|
I am closing then. @perimosocordiae is there a plan to actually return a 1d for CSR/CSC arrays? |
|
It's not official yet, but personally I think it makes sense to return 1d COO format for CSR/CSC indexing. |
Reference issue
None
What does this implement/fix?
This PR is a workaround the current
NotImplementedError:It makes sparse arrays and sparse matrices behaving consistently in this regard.