我有四个方形矩阵,尺寸为3Nx3N,称为A,B,C和D.
我想将它们组合在一个矩阵中.带有for循环的代码如下:
import numpy N = 3 A = numpy.random.random((3*N, 3*N)) B = numpy.random.random((3*N, 3*N)) C = numpy.random.random((3*N, 3*N)) D = numpy.random.random((3*N, 3*N)) final = numpy.zeros((6*N, 6*N)) for i in range(N): for j in range(N): for k in range(3): for l in range(3): final[6*i + k][6*j + l] = A[3*i+k][3*j+l] final[6*i + k + 3][6*j + l + 3] = B[3*i+k][3*j+l] final[6*i + k + 3][6*j + l] = C[3*i+k][3*j+l] final[6*i + k][6*j + l + 3] = D[3*i+k][3*j+l]
是否有可能以numpythonic方式编写前面的for循环?