bundles / scipy 1.17.1 / scipy / sparse / _construct / expand_dims
function
scipy.sparse._construct:expand_dims
source: /scipy/sparse/_construct.py :32
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 arrayaxis: 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 arrayA 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✓
Aliases
-
scipy.sparse.expand_dims