本文介绍了Python如何在numpy中合并两个矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Python的新手,在numpy中挣扎,希望有人能帮助我,谢谢!
new to Python, struggling in numpy, hope someone can help me, thank you!
from numpy import *
A = matrix('1.0 2.0; 3.0 4.0')
B = matrix('5.0 6.0')
C = matrix('1.0 2.0; 3.0 4.0; 5.0 6.0')
print "A=",A
print "B=",B
print "C=",C
结果:
A= [[ 1. 2.]
[ 3. 4.]]
B= [[ 5. 6.]]
C= [[ 1. 2.]
[ 3. 4.]
[ 5. 6.]]
问题:如何像Matlab C=[A;B]
中那样使用A和B生成C?
Question: how to use A and B to generate C, like in matlab C=[A;B]
?
推荐答案
>>> import numpy as np
>>> np.concatenate((A, B))
matrix([[ 1., 2.],
[ 3., 4.],
[ 5., 6.]])
这篇关于Python如何在numpy中合并两个矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!