bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / sparse / _construct / expand_dims
function
scipy.sparse._construct:expand_dims
source: build-install/usr/lib/python3.14/site-packages/scipy/sparse/_construct.py:30
Signature
def expand_dims(A, /, axis = 0)Summary
Add trivial axes to an array. Shape gets a 1 inserted at position axis.
Parameters
A: sparse arrayInput array.
axis: intPosition in the expanded axes where the new axis (or axes) is placed. For a dimension
Narray, a valid axis is an integer on the closed-interval[-N-1, N]. Negative values work from the end of the shape.0prepends an axis, as does-N-1.-1appends an axis, as doesN. The new axis has shape1and indices are created with the value0.
Returns
out: sparse arrayAn expanded copy output in COO format with the same dtype as
A.
Raises
: ValueErrorIf provided a non-integer or out of range
[-N-1, N]axis, whereNisA.ndim.
Examples
from scipy.sparse import csr_array, expand_dims A = csr_array([[1, 2], [2, 0]]) A.shape expand_dims(A, axis=1).shape✓
(2, 1, 2)
Aliases
scipy.sparse.expand_dims