Numpy pad返回值错误

时间:2018-06-02 01:38:46

标签: python arrays image numpy padding

我正在使用numpy进行图像数组填充,这是我的代码:

# padding function pads the patches in a minibatch to the size of the maximum width in the batch
def padding(batch):
    max_width = maxwidth(batch)
    new_batch = []
    for patch in batch:
        width = patch.shape[1]
        difference = max_width - width
        patch = np.expand_dims(patch, axis=2)
        before = int(np.floor(difference/2))
        after = int(difference - before)
        new_patch = np.pad(patch, [(before, after), (before, after)], 'constant', constant_values = 0)
        new_batch.append(new_patch)
    array_batch = np.stack(new_batch)

    return array_batch

我在一个批处理(numpy 2d数组的python列表)上运行它 它返回:

ValueError: Unable to create correctly shaped tuple from [(40, 40), (40, 40)]

任何人都知道为什么?提前谢谢。

0 个答案:

没有答案