0

I have an array image with BGR values, it has dimensions 11x11x3. I want to select all indices of a specific color using numpy.where but I get an error message. Why?

indices = np.where( (image[:,:,1] == 55) and (image[:,:,2] == 32))

Error:

"ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"

  • Use `&` instead of `and`. – jdehesa Jun 15 '20 at 16:42
  • `and` is a scalar Python operator. Expressions like `(image[:,:,1] == 55)` produce a boolean array (with more than one element). Their use with `and` produces this `ambiguity` error. `np.logical_and` (or operator `&`) works with arrays. – hpaulj Jun 15 '20 at 17:08

0 Answers0