[英]initialize matrix with vectors Python
I want to initialize a Matrix with 3 vectors. 我想用3个向量初始化一个矩阵。 The special part about is that I want the vectors to be the columns the matrix.
关于的特殊部分是我希望向量成为矩阵的列。
Vx= np.zeros((npoints,))
Vy=np.zeros((npoints,))
Vz=np.zeros((npoints,))
V=np.matrix(([Vx,Vy,Vz]))
Now the problem here is that the vectors form the rows of the matrix. 现在的问题是向量形成矩阵的行。 How can I fix that?
我该如何解决?
您可以使用np.column_stack
:
V = np.column_stack([Vx, Vy, Vz])
numpy中有一个速记:
V = np.c_[Vx, Vy, Vz]
unutbu解决方案的替代方法是使用np.vstack
或np.hstack
V = np.matrix(np.vstack((Vx, Vy, Vz)).T)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.