I couldn't find a straightforward way to compare two (multidimensional in my case) arrays the in a lexicographic way.
Ie.
a = [1,2,3,4]
b = [4,0,1,6]
For a < b
I want to get true
where I get [true, false, false, true]
For a > b
I want to get false
where I get [false, true, true, false]
If the question is just about finding whether a
is <
or >
than b
, then the following should work.
def fn(a, b):
# finds index of the first non matching element
idx = np.where( (a>b) != (a<b) )[0][0]
if a[idx] < b[idx]: print "a < b"
if a[idx] > b[idx]: print "a > b"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With