numpy.rollaxis() function with example in python
numpy.rollaxis(): This function roll the specified axis backwards, until it lies in a given position.
Syntax: numpy.rollaxis(a, axis, start=0)
This function continues to be supported for backward compatibility, but you should prefer moveaxis. The moveaxis function was added in NumPy 1.11.
Parameters:
a : ndarray
Input array.
axis : int
The axis to roll backwards. The positions of the other axes do not change relative to one another.
start : int, optional
The axis is rolled until it lies before this position. The default, 0, results in a “complete” roll.
Returns:
res : ndarray
For NumPy >= 1.10.0 a view of a is always returned. For earlier NumPy versions a view of a is returned only if the order of the axes is changed, otherwise the input array is returned.
import numpy as np
a = np.zeros((3,4,5,6))
b = np.rollaxis(a, 3, 1).shape
print(b)
Output:
(3, 6, 4, 5)