【发布时间】:2020-01-29 00:39:22
【问题描述】:
我有 RGB 图像作为 numpy 数组,我想替换为某个像素值:
import numpy as np
import random
def rgb():
L = [1]*3
return [random.randrange(0, 256,1)for l in L]
def makeDummyData():
#creates list of lists with 3 rgb, which contains values to replace (x)
L = [1]*10000
L = [rgb() for l in L]
x = L[0]
for i in range(500):
L[i] = x
return L, x
L, x = makeDummyData()
a = np.array(L).reshape(-1, 3)
a = np.array(a).reshape(100, 100, 3)
b = np.where(a == (np.array(x), [255,255,255], a))
print(b)
而不是返回一个数组,其中目标值被替换,输出是 (array([], dtype=int64),)
【问题讨论】:
-
我觉得你的括号有点不对。