Python numpy.moveaxis()函数

Python numpy.moveaxis()函数

numpy.moveaxis()函数将一个数组的轴移动到新的位置。其他轴保持原来的顺序。

语法 : numpy.moveaxis(arr, source, destination)
参数 :
arr : [ndarray] 输入阵列。
source : [ int or sequence of int] 要移动的轴的原始位置。这些必须是唯一的。
destination: [int或int序列] 每个原始轴的目的地位置。这些也必须是唯一的。
返回: [ndarray] 具有移动轴的数组。这个数组是输入数组的一个视图。

代码#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)

输出 :

(2, 3, 4, 1)

代码#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)

输出 :

(4, 1, 2, 3)

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Numpy 数组操作