Mar-31-2021, 03:57 PM
Your problem is not the comparison, it is the result of the comparison. When you compare two numpy arrays the result is an array of bool, not True or False
import numpy as np a = np.array([1, 2, 3]) b = np.array([2, 3, 4]) print(a < b) if a < b: print('True')
Output:[ True True True]
Traceback (most recent call last):
File "c:/Users/hystadd/Documents/python/sandbox/junk.py", line 7, in <module>
if a < b:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
The comparison worked fine, producing an array [ True True True]. This is very similar to what happens when you compare arrays in MATLAB (just replace True/False with 1/0). The problem is converting an array of bool to True or False. The error message tells you how to do this.import numpy as np a = np.array([1, 2, 3]) b = np.array([2, 3, 4]) print(a < b) if all(a < b): print('True')