我有一个4Dnumpy数组,但每个元素都是一个大小可变的3D体积。从本质上讲,它是一份数量众多的3D卷列表。所以numpy数组的形状是...
(Pdb) batch_x.shape
(3,)将元素i放在列表中,它看起来像这样...
(Pdb) batch_x[i].shape
(7, 70, 66)我尝试用下面的代码为每个3D卷填充零...
for i in range(batch_size):
pdb.set_trace()
batch_x[i] = np.lib.pad(batch_x[i], (n_input_z - int(batch_x[i][:,0,0].shape[0]),
n_input_x - int(batch_x[i][0,:,0].shape[0]),
n_input_y - int(batch_x[i][0,0,:].shape[0])),
'constant', constant_values=(0,0,0))
batch_y[i] = np.lib.pad(batch_y[i], (n_input_z - int(batch_y[i][:,0,0].shape[0]),
n_input_x - int(batch_y[i][0,:,0].shape[0]),
n_input_y - int(batch_y[i][0,0,:].shape[0])),
'constant', constant_values=(0,0,0))错误如下所示...
*** ValueError: Unable to create correctly shaped tuple from (3, 5, 9)
我正在尝试填充每个3D体积,使它们都具有相同的形状-- [10,75,75]。记住,就像我上面展示的那样,batch_x[i].shape = (7,70,66),所以错误消息至少告诉我我的尺寸应该是正确的。
作为证据,调试...
(Pdb) int(batch_x[i][:,0,0].shape[0])
7
(Pdb) n_input_z
10
(Pdb) (n_input_z - int(batch_x[i][:,0,0].shape[0]))
3发布于 2016-08-16 07:58:56
因此,除去无关紧要的东西,问题是:
In [7]: x=np.ones((7,70,66),int)
In [8]: np.pad(x,(3,5,9),mode='constant',constant_values=(0,0,0))
...
ValueError: Unable to create correctly shaped tuple from (3, 5, 9)看起来在定义pad的输入时出现了问题。我用得不多,但我记得每个维度的开始和结束都需要pad大小。
从它的文档中:
pad_width : {sequence, array_like, int}
Number of values padded to the edges of each axis.
((before_1, after_1), ... (before_N, after_N)) unique pad widths
for each axis.因此,让我们尝试一下元组的元组:
In [13]: np.pad(x,((0,3),(0,5),(0,9)), mode='constant', constant_values=0).shape
Out[13]: (10, 75, 75)你能从那里接下来吗?
https://stackoverflow.com/questions/38963610
复制相似问题