dpnp.swapaxes

dpnp.swapaxes(a, axis1, axis2)[source]

Interchange two axes of an array.

For full documentation refer to numpy.swapaxes.

Parameters:
  • a ({dpnp.ndarray, usm_ndarray}) -- Input array.

  • axis1 (int) -- First axis.

  • axis2 (int) -- Second axis.

Returns:

out -- An array with with swapped axes. A view is returned whenever possible.

Return type:

dpnp.ndarray

Notes

If a has rank (i.e., number of dimensions) N, a valid axis must be in the half-open interval [-N, N).

Examples

>>> import dpnp as np
>>> x = np.array([[1, 2, 3]])
>>> np.swapaxes(x, 0, 1)
array([[1],
       [2],
       [3]])
>>> x = np.array([[[0,1],[2,3]],[[4,5],[6,7]]])
>>> x
array([[[0, 1],
        [2, 3]],
       [[4, 5],
        [6, 7]]])
>>> np.swapaxes(x,0,2)
array([[[0, 4],
        [2, 6]],
       [[1, 5],
        [3, 7]]])