NumPy: Move axes of an array to new positions
NumPy: Array Object Exercise-53 with Solution
Write a NumPy program to move the specified axis backwards, until it lies in a given position.
Move the following 3rd array axes to first position.
import numpy as np x = np.ones((2,3,4,5)) print(np.rollaxis(x, 3, 1).shape)
(2, 5, 3, 4)
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a NumPy program to move axes of an array to new positions. Other axes remain in their original order.
Next: Write a NumPy program to convert specified inputs to arrays with at least one dimension.
What is the difficulty level of this exercise?
New Exercises:R Programming