scipy.sparse.
expand_dims#
- scipy.sparse.expand_dims(A, /, *, axis=0)[source]#
Add trivial axes to an array. Shape gets a
1inserted at position axis.- Parameters:
- Asparse array
- axisint
Position 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:
- outsparse array
A expanded copy output in COO format with the same dtype as A.
- Raises:
- ValueError
If 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 (2, 2) >>> expand_dims(A, axis=1).shape (2, 1, 2)