Answer the question
In order to leave comments, you need to log in
How to solve ValueError: The truth value...?
There is a large array, when I try to sort through it, I get
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
cleared_img_data = array(["+" if rgb != bg_color else "." for rgb in img_data])
Answer the question
In order to leave comments, you need to log in
numpy hints that the expression rgb != bg_color will return not a boolean value, but an array of boolean values - the results of comparing each element. In other words,
print(numpy.array([1, 2, 3]) != numpy.array([1, 2, 4])) will print [False, False, True]
As a result, it is not clear whether such an array should be considered true or false if it has several values and they are different.
The warning tells you how to fix it.
If you need any mismatch, then write (rgb != bg_color).any().
If you want all three color channels to be different, then (rgb != bg_color).all().
But to be honest, cleared_img_data is some weird array.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question