Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python将矩阵列表转换为单个矩阵_Python_Arrays_Numpy_Sorting - Fatal编程技术网

python将矩阵列表转换为单个矩阵

python将矩阵列表转换为单个矩阵,python,arrays,numpy,sorting,Python,Arrays,Numpy,Sorting,从for循环中,我得到一个矩阵列表。每个矩阵作为一个维数[m*n]。我把spettri_cp1称为矩阵列表。目前我有12个矩阵。我想建立一个维度为[m,12*n]的矩阵。我尝试使用此循环,但再次获得一个新列表。 列表的维度spettrou cp1=[12224,18] mat_cp1=[] #i define the new matrix for i in range(12): for j in range(18): frame = spettri_cp1[i,:,:]

从for循环中,我得到一个矩阵列表。每个矩阵作为一个维数[m*n]。我把spettri_cp1称为矩阵列表。目前我有12个矩阵。我想建立一个维度为[m,12*n]的矩阵。我尝试使用此循环,但再次获得一个新列表。 列表的维度spettrou cp1=[12224,18]

mat_cp1=[]  #i define the new matrix
for i in range(12):
    for j in range(18):
        frame = spettri_cp1[i,:,:] # from the list i extract the first matrix
        spettro = frame[:,j] # from the first matrix i extract the single column
mat_cp1.append(spettro) # i append all the extracted column to build the new matrix

出什么问题了?

最后一行的缩进似乎不正确
mat_cp1
刚好等于最后一个
spettro
值。谢谢。在循环之后,我还添加了一个创建矩阵的命令:mat_cp1=np.array(mat_cp1),请您提供一个?
np.concatenate();np.重塑()
import random

m=3
n=4
listOfMatrices = [ [[random.random() for k in range(m)] for p in range(n)] for i in range(12)] #first create a list of random 12 matrix with m=3, n=4
flatList = [i for j in listOfMatrices for i in j]
flatList  = list(map(list, zip(*flatList ))) # transpose to get the desired shape