Skip to content

DOC: Undocumented dtype change with sp.sparse.csr_array(sp.sparse.spdiags(...)) vs. sp.sparse.diags_array(...) #23102

@Peiffap

Description

@Peiffap

Issue with current documentation:

While doing code maintenance in networkx/networkx#8080, I stumbled upon the following behavior while trying to use the new-ish tools for building sparse arrays:

>>> import scipy as sp
>>> A = sp.sparse.csr_array([[1, 2], [3, 4]])
>>> s = A.sum(axis=1)
>>> n, m = A.shape
>>> sp.sparse.csr_array(sp.sparse.spdiags(s, 0, m, n, format="csr")).toarray()
array([[3, 0],
       [0, 7]])
>>> sp.sparse.diags_array(s, format="csr").toarray()
array([[3., 0.],
       [0., 7.]])

The default dtype seems to have changed, but this isn't documented anywhere (that I know of!). Please let me know if I'm doing something wrong, or if I just didn't look hard enough.

Idea or request for content:

No response

Additional context (e.g. screenshots, GIFs)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues related to the SciPy documentation. Also check https://github.com/scipy/scipy.orgscipy.sparse

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions