【发布时间】:2020-05-22 16:20:07
【问题描述】:
我想在循环中创建一个包含不同大小矩阵的容器,作为单元格或列表。我创建了一个这样的python代码:
W = []
W_tot = []
for i in range(0,layer_number): #layer_numer = number of matrix to be created
row_W = int(input('NumRow = ')) #number of row of the nth matrix
col_W = int(input('Numcols = ')) #number of cols of the nth matrix
W = 0.5*np.random.rand(row_W,col_W) #creation of the nth matrix with random number
cells = np.array([W]) #insert of the created matrix in a cell
无论如何,我总是出错。当然,我在创建一个包含循环每一步创建的所有矩阵的单元格时犯了一个错误。
【问题讨论】:
-
请包含错误
-
我没有收到错误,但单元格的尺寸错误。例如,使用 layer_number =2,即我想创建两个矩阵,我得到一个维度为 (1,20,9) 的单元格,其中 20 是行数,9 是列数。我想要获得的是一个尺寸为 (2,..) 的单元格。