xp_moveaxis_to_end¶
- xp_moveaxis_to_end(x: Any, source: int, /, *, xp: ModuleType | None = None) Any[source][source]¶
Move an axis to the end of the array.
- Parameters:
x (
Array) – The input array.source (
int) – The source axis to move.xp (
module, optional) –- The array API namespace to use. If not provided, the namespace is
inferred from the array.
- Returns:
Array with the source axis moved to the end.
- Return type:
Array
Notes
- This is a temporary substitute for xp.moveaxis, which is not yet
available in all backends or covered by array_api_compat.
Examples
>>> import numpy as np >>> x = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) >>> x.shape (2, 2, 2) >>> y = xp_moveaxis_to_end(x, 0, xp=np) >>> y.shape (2, 2, 2) >>> # The first axis (axis 0) is now the last axis >>> np.array_equal(y, np.moveaxis(x, 0, -1)) True