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

# permute_dims

scipy.sparse.permute_dims(A, axes=None, copy=False)

  Permute the axes of the sparse array A to the order axes.

  Parameters:
    A sparse array
    axes tuple or list of ints, optional

      If specified, it must be a tuple or list which contains a permutation of `[0, 1, ..., N-1]` where `N` is `A.ndim`. The ith axis of the returned array will correspond to the axis numbered `axes[i]` of the input. If not specified, defaults to `range(A.ndim)[::-1]`, which reverses the order of the axes.

    copy bool, optional (default: False)

      Whether to return the permutation as a copy. If False, an in-place permutation is provided if possible depending on format.

  Returns:
    out sparse array in COO format

      A copy of A with permuted axes.

  Raises:
    ValueError

      If provided a non-integer or out of range `[-N, N-1]` axis, where `N` is `A.ndim`.

  Examples

      >>> from scipy.sparse import coo_array, permute_dims
      >>> A = coo_array([[[1, 2, 3], [2, 0, 0]]])
      >>> A.shape
      (1, 2, 3)
      >>> permute_dims(A, axes=(1, 2, 0)).shape
      (2, 3, 1)