I’m trying to run code containing the following:
if np.any(1.5<=np.abs(Array1 - Array2)<=2):
return True
However, when I run this, I get the error: Truth value of an array with multiple elements is ambiguous, use a.any() or a.all(). How do I implement this inequality condition in the np.any() function without error?
>Solution :
It seems like you can’t quite do concise inequalities with numpy like you can in the rest of Python. Instead, just do two separate conditions and combine them:
tmp = np.abs(Array1 - Array2)
if np.any((1.5 <= tmp) & (tmp <= 2)):
return True