pythonnp.rollaxis
时间: 2023-11-04 13:44:49 浏览: 57
The numpy rollaxis() function is used to roll the specified axis backwards, until it lies in a specified position. This function is very useful when working with multi-dimensional arrays, as it allows you to change the shape of the array without changing the data.
The function takes three arguments:
numpy.rollaxis(arr, axis, start)
Here,
- arr: Input array.
- axis: The axis to roll backwards. It can be any integer or tuple of integers. If a tuple is specified, the first element is the axis to roll, and the second element is the new position of the rolled axis.
- start: The new position of the rolled axis. It can be any integer.
The function returns a new array with the specified axis rolled to the new position.
Example:
Consider the following 3D array:
arr = np.ones((3, 4, 5))
To roll the second axis to the end:
np.rollaxis(arr, 1, 3)
This will return a new array with shape (3, 5, 4), where the second axis has been rolled to the end.
阅读全文