blosc2.permute_dims#

blosc2.permute_dims(arr: NDArray, axes: tuple[int] | list[int] | None = None, **kwargs: Any) NDArray#

Permutes the axes (dimensions) of an array.

Parameters:
  • arr (NDArray) – The input array.

  • axes (tuple[int], list[int], optional) – The desired permutation of axes. If None, the axes are reversed by default. If specified, axes must be a tuple or list representing a permutation of [0, 1, ..., N-1], where N is the number of dimensions of the input array. Negative indices are also supported. The i-th axis of the result will correspond to the axis numbered axes[i] of the input.

  • kwargs (Any, optional) – Keyword arguments that are supported by the empty() constructor.

Returns:

out – A Blosc2 NDArray with axes transposed.

Return type:

NDArray

Raises:

ValueError – If axes is not a valid permutation of the dimensions of arr.

References

numpy.transpose

permute_dims

Examples

For 2-D arrays it is the matrix transposition as usual:

>>> import blosc2
>>> a = blosc2.arange(1, 10).reshape((3, 3))
>>> a[:]
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])
>>> at = blosc2.permute_dims(a)
>>> at[:]
array([[1, 4, 7],
       [2, 5, 8],
       [3, 6, 9]])

For 3-D arrays:

>>> import blosc2
>>> a = blosc2.arange(1, 25).reshape((2, 3, 4))
>>> a[:]
array([[[ 1,  2,  3,  4],
        [ 5,  6,  7,  8],
        [ 9, 10, 11, 12]],
       [[13, 14, 15, 16],
        [17, 18, 19, 20],
        [21, 22, 23, 24]]])
>>> at = blosc2.permute_dims(a, axes=(1, 0, 2))
>>> at[:]
array([[[ 1,  2,  3,  4],
        [13, 14, 15, 16]],
       [[ 5,  6,  7,  8],
        [17, 18, 19, 20]],
       [[ 9, 10, 11, 12],
        [21, 22, 23, 24]]])