简体   繁体   中英

Numpy.where uses

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])

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])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM