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)