permute_dims#

ivy.permute_dims(x, /, axes, *, copy=None, out=None)[source]#

Permutes the axes (dimensions) of an array x.

Parameters:
  • x (Union[Array, NativeArray]) – input array.

  • axes (Tuple[int, ...]) – tuple containing a permutation of (0, 1, …, N-1) where N is the number of axes (dimensions) of x.

  • copy (Optional[bool], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning a view of the input array.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array containing the axes permutation. The returned array must have the same data type as x.

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Examples

With ivy.Array input:

>>> x = ivy.array([[1, 2, 3], [4, 5, 6]])
>>> y = ivy.permute_dims(x, axes=(1, 0))
>>> print(y)
ivy.array([[1, 4],
           [2, 5],
           [3, 6]])
>>> x = ivy.zeros((2, 3))
>>> y = ivy.permute_dims(x, axes=(1, 0))
>>> print(y)
ivy.array([[0., 0.],
           [0., 0.],
           [0., 0.]])

With one ivy.Container input:

>>> x = ivy.Container(a=ivy.array([[0., 1. ,2.]]), b=ivy.array([[3., 4., 5.]]))
>>> y = ivy.permute_dims(x, axes=(1, 0))
>>> print(y)
{
    a: ivy.array([[0.],
                  [1.],
                  [2.]]),
    b: ivy.array([[3.],
                  [4.],
                  [5.]])
}
>>> x = ivy.Container(a=ivy.array([[0., 1., 2.]]), b = ivy.array([[3., 4., 5.]]))
>>> y = ivy.Container(a=ivy.zeros((3, 1)), b= ivy.zeros((3, 1)))
>>> ivy.permute_dims(x, axes=(1, 0), out=y)
>>> print(y)
{
    a: ivy.array([[0.],
                  [1.],
                  [2.]]),
    b: ivy.array([[3.],
                  [4.],
                  [5.]])
}
Array.permute_dims(self, /, axes, *, copy=None, out=None)[source]#

ivy.Array instance method variant of ivy.permute_dims. This method simply wraps the function, and so the docstring for ivy.permute_dims also applies to this method with minimal changes.

Parameters:
  • self (Array) – input array.

  • axes (Tuple[int, ...]) – tuple containing a permutation of (0, 1, …, N-1) where N is the number of axes (dimensions) of x.

  • copy (Optional[bool], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning a view of the input array.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array containing the axes permutation. The returned array must have the same data type as x.

Examples

With ivy.Array input:

>>> x = ivy.array([[1, 2, 3], [4, 5, 6]])
>>> y = x.permute_dims(axes=(1, 0))
>>> print(y)
ivy.array([[1, 4],
           [2, 5],
           [3, 6]])
>>> x = ivy.zeros((2, 3))
>>> y = x.permute_dims(axes=(1, 0))
>>> print(y)
ivy.array([[0., 0.],
           [0., 0.],
           [0., 0.]])
Container.permute_dims(self, /, axes, *, copy=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container instance method variant of ivy.permute_dims. This method simply wraps the function, and so the docstring for ivy.permute_dims also applies to this method with minimal changes.

Parameters:
  • self (Container) – input container.

  • axes (Union[Tuple[int, ...], Container]) – tuple containing a permutation of (0, 1, …, N-1) where N is the number of axes (dimensions) of x.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • out (Optional[Container], default: None) – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Container

Returns:

ret – A container with the elements of self permuted along the given axes.

Examples

>>> x = ivy.Container(a=ivy.array([[0., 1., 2.]]), b=ivy.array([[3., 4., 5.]]))
>>> y = x.permute_dims(axes=(1, 0))
>>> print(y)
{
    a:ivy.array([[0.],[1.],[2.]]),
    b:ivy.array([[3.],[4.],[5.]])
}