How to compare two array of numpy to get which one is greater than another one
When you compare a array to another array with numpy module. You would meet a error like this:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
In order to solve this problem. Use np.all() as follows :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
>>> import numpy as np
>>> a = np.array([1,2,3,4,5])
>>> b = np.array([6,7,8,9,10])
>>> c = np.array([1,2,3,9,5])
>>> if np.all(a > b):
... print("test")
... else:
... print("what")
...
what
>>> if np.any(c > a):
... print("any")
...
any