首页 > 解决方案 > MEMORY ISSUE: MemoryError: Unable to allocate array with shape (4104, 1048576, 3) and data type int32

问题描述

我有一个如下所示的工作代码,但是当我的 rgbL 非常大时,我收到了这个错误:MEMORY ISSUE: MemoryError: Unable to allocate array with shape (4104, 1048576, 3) and data type int32

如何解决这个问题?

sh = img.shape
img = img.reshape(-1, 3)
img[np.where(((rgbL[:,None,:]-img)==0).all(axis=2))[1]]=np.array([255,0,0])
img = img.reshape(sh)

其中 img 和 rgbL 定义为:

img:
[[20  45  40]
[ 30  45  60]
[  0   1   2]
[ 70  50 100]
[  4   5   6]]
rgbL:
[[ 20,  45,  40],
[ 30,  45,  60],
  ..........
[ 70,  50, 100]]

标签: pythonnumpy

解决方案


推荐阅读