rot90#

ivy.rot90(m, /, *, copy=None, k=1, axes=(0, 1), out=None)[source]#

Rotate an array by 90 degrees in the plane specified by axes. Rotation direction is from the first towards the second axis.

Parameters:
  • m (Union[Array, NativeArray]) – Input array of two or more dimensions.

  • 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.

  • k (int, default: 1) – Number of times the array is rotated by 90 degrees.

  • axes (Tuple[int, int], default: (0, 1)) – The array is rotated in the plane defined by the axes. Axes must be different.

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

Return type:

Array

Returns:

ret – A rotated view of m.

Examples

With ivy.Array input: >>> m = ivy.array([[1,2], [3,4]]) >>> ivy.rot90(m) ivy.array([[2, 4],

[1, 3]])

>>> m = ivy.array([[1,2], [3,4]])
>>> ivy.rot90(m, k=2)
ivy.array([[4, 3],
       [2, 1]])
>>> m = ivy.array([[[0, 1],                        [2, 3]],                       [[4, 5],                        [6, 7]]])
>>> ivy.rot90(m, k=2, axes=(1,2))
ivy.array([[[3, 2],
        [1, 0]],
[[7, 6],

[5, 4]]])

With ivy.NativeArray input: >>> m = ivy.native_array([[1,2], [3,4]]) >>> ivy.rot90(m) ivy.array([[2, 4],

[1, 3]])

>>> m = ivy.native_array([[1,2], [3,4]])
>>> ivy.rot90(m, k=2)
ivy.array([[4, 3],
       [2, 1]])
>>> m = ivy.native_array([[[0, 1],                               [2, 3]],                              [[4, 5],                               [6, 7]]])
>>> ivy.rot90(m, k=2, axes=(1,2))
ivy.array([[[3, 2],
        [1, 0]],
[[7, 6],

[5, 4]]])

Array.rot90(self, /, *, copy=None, k=1, axes=(0, 1), out=None)[source]#

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

Parameters:
  • self (Array) – Input array of two or more dimensions.

  • 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.

  • k (int, default: 1) – Number of times the array is rotated by 90 degrees.

  • axes (Tuple[int, int], default: (0, 1)) – The array is rotated in the plane defined by the axes. Axes must be different.

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

Return type:

Array

Returns:

ret – Array with a rotated view of input array.

Examples

>>> m = ivy.array([[1,2], [3,4]])
>>> m.rot90()
ivy.array([[2, 4],
       [1, 3]])
>>> m = ivy.array([[1,2], [3,4]])
>>> m.rot90(k=2)
ivy.array([[4, 3],
       [2, 1]])
>>> m = ivy.array([[[0, 1],                            [2, 3]],                           [[4, 5],                            [6, 7]]])
>>> m.rot90(k=2, axes=(1,2))
ivy.array([[[3, 2],
        [1, 0]],
[[7, 6],

[5, 4]]])

Container.rot90(self, /, *, copy=None, k=1, axes=(0, 1), key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Union[Container, Array, NativeArray]) – Input array of two or more dimensions.

  • k (Union[int, Container], default: 1) – Number of times the array is rotated by 90 degrees.

  • axes (Union[Tuple[int, int], Container], default: (0, 1)) – The array is rotated in the plane defined by the axes. Axes must be different.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

  • 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 – Container with a rotated view of input array.

Examples

>>> m = ivy.Container(a=ivy.array([[1,2], [3,4]]),
...                   b=ivy.array([[1,2,3,4],[7,8,9,10]]))
>>> n = m.rot90()
>>> print(n)
{
    a: ivy.array([[2, 4],
                  [1, 3]]),
    b: ivy.array([[4, 10],
                  [3, 9],
                  [2, 8],
                  [1, 7]])
}