moveaxis#
- ivy.moveaxis(a, source, destination, /, *, copy=None, out=None)[source]#
Move axes of an array to new positions..
- Parameters:
a (
Union
[Array
,NativeArray
]) – The array whose axes should be reordered.source (
Union
[int
,Sequence
[int
]]) – Original positions of the axes to move. These must be unique.destination (
Union
[int
,Sequence
[int
]]) – Destination positions for each of the original axes. These must also be unique.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
[Union
[Array
,NativeArray
]], default:None
) – optional output array, for writing the result to.
- Return type:
Union
[Array
,NativeArray
]- Returns:
ret – Array with moved axes. This array is a view of the input array.
Examples
With
ivy.Array
input: >>> x = ivy.zeros((3, 4, 5)) >>> ivy.moveaxis(x, 0, -1).shape (4, 5, 3) >>> ivy.moveaxis(x, -1, 0).shape (5, 3, 4)
- Array.moveaxis(self, source, destination, /, *, copy=None, out=None)[source]#
ivy.Array instance method variant of ivy.moveaxis. This method simply wraps the function, and so the docstring for ivy.unstack also applies to this method with minimal changes.
- Parameters:
a – The array whose axes should be reordered.
source (
Union
[int
,Sequence
[int
]]) – Original positions of the axes to move. These must be unique.destination (
Union
[int
,Sequence
[int
]]) – Destination positions for each of the original axes. These must also be unique.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.
- Return type:
Array
- Returns:
ret – Array with moved axes. This array is a view of the input array.
Examples
>>> x = ivy.zeros((3, 4, 5)) >>> x.moveaxis(0, -1).shape (4, 5, 3) >>> x.moveaxis(-1, 0).shape (5, 3, 4)
- Container.moveaxis(self, source, destination, /, *, copy=None, out=None)[source]#
ivy.Container instance method variant of ivy.moveaxis. This method simply wraps the function, and so the docstring for ivy.flatten also applies to this method with minimal changes.
- Parameters:
self (
Container
) – The container with the arrays whose axes should be reordered.source (
Union
[int
,Sequence
[int
],Container
]) – Original positions of the axes to move. These must be unique.destination (
Union
[int
,Sequence
[int
],Container
]) – Destination positions for each of the original axes. These must also be unique.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.
- Return type:
Container
- Returns:
ret – Container including arrays with moved axes.
Examples
With one
ivy.Container
input: >>> x = ivy.Container(a=ivy.zeros((3, 4, 5)), b=ivy.zeros((2,7,6))) >>> x.moveaxis(, 0, -1).shape {a: (4, 5, 3) b: (7, 6, 2)
}