我有一个 4D numpy 数组,但每个元素都是一个可变大小的 3D 体积。本质上,它是一个 3D 卷的 numpy 列表。所以 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