首页 > 解决方案 > 重塑/填充 Numpy 数组 - Python

问题描述

我有一个像这样的多个 numpy 数组:

[1, 5, 0, 0]
[2, 1, 3, 1]
[1, 3, 4, 1]

我所有的数组都有不同的值和形状。

我想编写一个函数,将我所有的数组填充到相同的形状。

目前,我正在做这样的事情(在 for 循环内):

width = int(7000 - size[0])
height = int(7000 - size[1])
data = np.pad(data, (width, height), 'constant', constant_values=(0,0))

其中 data 是正在编辑的数组,而 7000x7000 是我最大的数组。

这给了我一个 MemoryError。

标签: pythonnumpy

解决方案


推荐阅读