创建分块矩阵的一种简单方法是numpy.bmat http://docs.scipy.org/doc/numpy/reference/generated/numpy.bmat.html(正如@inquisitiveIdiot 所指出的)。根据您要创建的块矩阵判断,您需要一个 3x2 的零矩阵:
>>> import numpy as np
>>> z = np.zeros( (3, 2) )
然后,您可以通过将块的 2x2 数组传递给来创建块矩阵numpy.bmat
:
>>> M = np.bmat( [[a, b], [z, c]] )
>>> M
matrix([[ 1., 2., 5., 6., 7.],
[ 3., 4., 8., 9., 10.],
[ 0., 0., 1., 2., 3.],
[ 0., 0., 4., 5., 6.],
[ 0., 0., 7., 8., 9.]])
另一种(IMO更复杂)方法是使用numpy.hstack http://docs.scipy.org/doc/numpy/reference/generated/numpy.hstack.html and numpy.vstack http://docs.scipy.org/doc/numpy/reference/generated/numpy.vstack.html.
>>> M = np.vstack( (np.hstack((a, b)), np.hstack((z, c))) )
>>> M
matrix([[ 1., 2., 5., 6., 7.],
[ 3., 4., 8., 9., 10.],
[ 0., 0., 1., 2., 3.],
[ 0., 0., 4., 5., 6.],
[ 0., 0., 7., 8., 9.]])