I have an array of pairs of ints. I'd like to reduce each pair using <, but np.less.reduce(..., axis=1)
which I expected to work, doesn't:
>>> np.less.reduce(np.array([[1, 2], [3, 1]]), axis=1)
array([False, False])
I wanted the result array([True, False])
. This surprised me, seeing that add.reduce
(yes, I know that can be just sum(...)
) does what I expect:
>>> np.add.reduce(np.array([[1, 2], [3, 1]]), axis=1)
array([3, 4])
What have I misunderstood?
CodePudding user response:
When doing
np.less.reduce([1,2])
it returns False
, so less.reduce does not work the way you want it to here.
Why not simply:
arr = np.array([[1, 2], [3, 1]])
np.less(arr[:,0], arr[:,1])