📜  Numpy ndarray.transpose()函数| Python

📅  最后修改于: 2022-05-13 01:55:29.223000             🧑  作者: Mango

Numpy ndarray.transpose()函数| Python

numpy.ndarray.transpose()函数返回轴转置的数组视图。
对于一维数组,这没有影响,因为转置向量只是相同的向量。对于二维数组,这是标准矩阵转置。对于 nD 数组,如果给定轴,则它们的顺序指示轴的排列方式。如果未提供轴且 arr.shape = (i[0], i[1], ... i[n-2], i[n-1]),则 arr.transpose().shape = (i[n -1], i[n-2], … i[1], i[0])。

代码#1:

# Python program explaining
# numpy.ndarray.transpose() function
  
# importing numpy as geek 
import numpy as geek
  
arr = geek.array([[5, 6], [7, 8]])
  
gfg = arr.transpose()
  
print( gfg )

输出 :

[[5 7]
 [6 8]]


代码#2:

# Python program explaining
# numpy.ndarray.transpose() function
  
# importing numpy as geek 
import numpy as geek
  
arr = geek.array([[5, 6], [7, 8]])
  
gfg = arr.transpose((1, 0))
  
print( gfg )

输出 :

[[5 7]
 [6 8]]