Skip to content

Sparse: document and test handling of explicit zeros #3343

@jnothman

Description

@jnothman

Some sparse matrix formats store explicit zero-valued elements (see e.g.

explicit zero values are included in this number
,
* explicit zeros are treated as nonzero.
,
* Explicit zeros in A are carried over to B.
).

I know that in some applications of sparse matrices in which implicit zeros have different semantics (e.g. unknown value), explicit zeros are exploited, such as for data imputation.

It seems explicit zeros are maintained in matrix conversion to CSR, CSC, BSR, COO and DOK, but not to LIL.

To my knowledge the properties of the sparse matrix implementations with respect to explicit zeros are undocumented and untested. I presume they should be.

For an example of inconsistency:

>>> A = sp.coo_matrix([[0]])
>>> A.nnz
0
>>> B = A.tocsr()
>>> B[0, 0] = 0
>>> B.nnz
1
>>> B = A.todok()
>>> B[0, 0] = 0
>>> B.nnz
0
>>> B = A.tolil()
>>> B[0, 0] = 0
>>> B.nnz
0

What is correct behaviour?

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expectedneeds-decisionItems that need further discussion before they are merged or closedscipy.sparse

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions