将 3D 矩阵转换为垂直级联的 1D 阵列
Converting a 3D matrix into vertically cascaded 1D arrays
下面这段代码中的for循环有没有捷径?
import numpy as np
ff = np.zeros((3,3,4))
gg = np.zeros((36,1))
ff[:,:,0] = 1
ff[:,:,1] = 2
ff[:,:,2] = 3
ff[:,:,3] = 4
for ii in xrange(4):
gg[ii*9:(ii+1)*9,0] = ff[:,:,ii].reshape((9,))
下面这段代码中的for循环有没有捷径?
import numpy as np
ff = np.zeros((3,3,4))
gg = np.zeros((36,1))
ff[:,:,0] = 1
ff[:,:,1] = 2
ff[:,:,2] = 3
ff[:,:,3] = 4
for ii in xrange(4):
gg[ii*9:(ii+1)*9,0] = ff[:,:,ii].reshape((9,))