Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

BUG: Slices of sparse matrices return incorrect dtype #3059

Closed
polyatail opened this Issue · 2 comments

2 participants

@polyatail

Sparse matrices, when sliced, will return a new matrix of the default dtype rather than the same dtype as initialized.

This is true of lil_matrix:

>>> a = scipy.sparse.lil_matrix((1, 100), dtype="string")
>>> a
<1x100 sparse matrix of type '<type 'numpy.string_'>'
    with 0 stored elements in LInked List format>
>>> a[0, 10:20]
<1x10 sparse matrix of type '<type 'numpy.int64'>'
    with 0 stored elements in LInked List format>

And of dok_matrix:

>>> a = scipy.sparse.dok_matrix((1, 100), dtype="string")
>>> a
<1x100 sparse matrix of type '<type 'numpy.string_'>'
    with 0 stored elements in Dictionary Of Keys format>
>>> a[0, 10:20]
<1x10 sparse matrix of type '<type 'numpy.float64'>'
    with 0 stored elements in Dictionary Of Keys format>
@pv
Owner
pv commented

Indeed. Note however that strings are not one of the supported sparse matrix data types, so many operations will simply not work, although this isn't checked on construction.

@polyatail

Still true of any data type. String is only the example.

@polyatail polyatail referenced this issue from a commit in polyatail/scipy
@polyatail polyatail Test dtype preservation in sparse matrix slicing
Addition to issue #3059
ab4644a
@pv pv closed this in 6f0e664
@andrenarchy andrenarchy referenced this issue from a commit in andrenarchy/scipy
@polyatail polyatail Fix #3059, wrong dtype for sliced sparse matrices 2fc6e18
@andrenarchy andrenarchy referenced this issue from a commit in andrenarchy/scipy
@polyatail polyatail Test dtype preservation in sparse matrix slicing
Addition to issue #3059
e00a30d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.