scipy 1.8.0 Pypi GitHub Homepage
Other Docs
AttributesNotesBackRef

Attributes

dtype : dtype

Data type of the matrix

shape : 2-tuple

Shape of the matrix

ndim : int

Number of dimensions (this is always 2)

nnz :

Number of nonzero elements

This is an efficient structure for constructing sparse matrices incrementally.

This can be instantiated in several ways:

dok_matrix(D)

with a dense matrix, D

dok_matrix(S)

with a sparse matrix, S

dok_matrix((M,N), [dtype])

create the matrix with initial shape (M,N) dtype is optional, defaulting to dtype='d'

Notes

Sparse matrices can be used in arithmetic operations: they support addition, subtraction, multiplication, division, and matrix power.

Allows for efficient O(1) access of individual elements. Duplicates are not allowed. Can be efficiently converted to a coo_matrix once constructed.

Dictionary Of Keys based sparse matrix.

Examples

>>> import numpy as np
... from scipy.sparse import dok_matrix
... S = dok_matrix((5, 5), dtype=np.float32)
... for i in range(5):
...  for j in range(5):
...  S[i, j] = i + j # Update element
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.sparse._dok.dok_matrix._update scipy.sparse._dok.isspmatrix_dok scipy.sparse._dok.dok_matrix

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/sparse/_dok.py#23
type: <class 'type'>
Commit: