python - Better way to create block matrices out of individual blocks in numpy? -


consider code

m=5;n=3; a11=np.random.rand(m,m); a12=np.random.rand(m,n); a21=np.random.rand(n,m); a22=np.random.rand(n,n); 

i new numpy , learning it. want create block matrix in following manner

rowblock1=np.concatenate((a11,a12),axis=1) rowblock2=np.concatenate((a21,a22),axis=1) block=np.concatenate((rowblock1,rowblock2),axis=0) 

is there more easy way it? eg:, in matlab

block=[[a11,a12];[a21,a22]] 

and done it.i understand reserved arrays.

there's bmat:

block = numpy.bmat([[a11, a12], [a21, a22]]) 

note creates matrix, rather array; can call asarray on result if want array.

bmat messing around stack frames let this:

block = numpy.bmat('a11,a12; a21,a22') 

Comments