bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / sparse / _dok / dok_array
ABCMeta
scipy.sparse._dok:dok_array
source: build-install/usr/lib/python3.14/site-packages/scipy/sparse/_dok.py:687
Signature
def dok_array(arg1, shape = None, dtype = None, copy = False, *, maxprint = None)Summary
Dictionary Of Keys based sparse array.
Extended Summary
This is an efficient structure for constructing sparse arrays incrementally.
This can be instantiated in several ways:
dok_array(D)
where D is a 2-D ndarray
dok_array(S)
with another sparse array or matrix S (equivalent to S.todok())
dok_array((M,N), [dtype])
create the array with initial shape (M,N) dtype is optional, defaulting to dtype='d'
Attributes
dtype: dtypeData type of the array
shape: 2-tupleShape of the array
ndim: intNumber of dimensions (this is always 2)
format: strThree letter code for the format of the array storage, e.g. 'dok'
nnz: intNumber of values stored in the array
size: intNumber of values stored in the array
T: dok_arrayThe transpose of the array
mT: dok_arrayThe matrix transpose of the array
Notes
Sparse arrays 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_array once constructed.
Examples
import numpy as np from scipy.sparse import dok_array S = dok_array((5, 5), dtype=np.float32) for i in range(5): for j in range(5): S[i, j] = i + j # Update element✓
Aliases
scipy.sparse.dok_array