'Numpy comparing vectors of length m and n resulting in boolean matrix of size m,n [duplicate]
I am wondering if there is a more efficient way to run the comparison (or really many other functions) using numpy.
a = np.array([1,2,5,7])
b = np.array([0,4,6])
np.repeat(a, len(b)).reshape(-1, len(b)) > b
> array([[ True, False, False],
[ True, False, False],
[ True, True, False],
[ True, True, True]])
Basically each output (m, n) is the comparison if A_m > B_n
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
