Skip to main content
`Ctrl`+`K`
scipy.sparse.

# expand_dims

scipy.sparse.expand_dims(A, /, *, axis=0)

  Add trivial axes to an array. Shape gets a `1` inserted at position axis.

  Parameters:
    A sparse array
    axis int

      Position in the expanded axes where the new axis (or axes) is placed. For a dimension `N` array, a valid axis is an integer on the closed-interval `[-N-1, N]`. Negative values work from the end of the shape. `0` prepends an axis, as does `-N-1`. `-1` appends an axis, as does `N`. The new axis has shape `1` and indices are created with the value `0`.

  Returns:
    out sparse 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, where `N` is `A.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)