参考:
https://www.cnblogs.com/cymwill/p/8358866.html
分析
Numpy相关的转置函数有T、transpose等。使一维数组转置可以使用reshape实现。
实现例子
import numpy as np
a = np.array([1,2,3,4,5])
print(a)
print(a.T)
print(a.transpose())
print(a.reshape(a.shape[0],1)
输出结果:
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
[[1]
[2]
[3]
[4]
[5]]
因此,要实现一维数组a转置,可以参考如下代码:
import numpy as np
a = np.array([1,2,3,4,5])
a = a.reshape(a.shape[0],1)