The Wayback Machine - https://web.archive.org/web/20240118171053/https://www.geeksforgeeks.org/numpy-moveaxis-function-python/
Open In App
Related Articles

numpy.moveaxis() function | Python

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

numpy.moveaxis() function move axes of an array to new positions. Other axes remain in their original order.

Syntax : numpy.moveaxis(arr, source, destination)
Parameters :
arr : [ndarray] input array.
source : [ int or sequence of int] Original positions of the axes to move. These must be unique.
destination : [ int or sequence of int] Destination positions for each of the original axes. These must also be unique.
Return : [ndarray] Array with moved axes. This array is a view of the input array.

Code #1 :




# Python program explaining
# numpy.moveaxis() function
  
# importing numpy as geek 
import numpy as geek
  
arr = geek.zeros((1, 2, 3, 4))
  
gfg = geek.moveaxis(arr, 0, -1).shape
  
print (gfg)


Output :

(2, 3, 4, 1)

 
Code #2 :




# Python program explaining
# numpy.moveaxis() function
  
# importing numpy as geek 
import numpy as geek
  
arr = geek.zeros((1, 2, 3, 4))
  
gfg = geek.moveaxis(arr, -1, 0).shape
  
print (gfg)


Output :

(4, 1, 2, 3)
Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 22 Apr, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials