问题
Use numpy.where to get all (R, G,B) in a numpy.array with a definite value of R, G and B
The problem is i'm not sure i can use numpy.where to get what i want :
i tried the following code :
L = numpy.array([[1,2,3],[1,1,1],[1,1,1]])
print(numpy.where(L==(1,1,1)))
(array([0, 1, 1, 1, 2, 2, 2], dtype=int64), array([0, 0, 1, 2, 0, 1, 2], dtype=int64))
and i understand it's returning me the coordinates of every element == 1 but i would like it to return the index in L of the element equal to (1,1,1) :
array([1,2])
回答1:
You are looking for numpy.nonzero together with np.all
(to ensure that each of RGB matches):
>>> numpy.nonzero(numpy.all(L == (1, 1, 1), axis=1))[0]
array([1, 2])
来源:https://stackoverflow.com/questions/55526150/numpy-where-uses