If I have an array like below, how can I detect that there is a tie of at least 3 or more values when using np.argmax()
?
examp = np.array([[4, 0, 1, 4, 4],
[5, 5, 1, 5, 5],
[1, 2, 2, 4, 1],
[4, 6, 1, 2, 4],
[1, 4, 3, 3, 3]])
np.argmax(examp, axis=1)
which gives an output:
array([0, 0, 3, 1, 1]
Taking the first row as an example, there is a "3-way tie". 3 values of 4
. np.argmax
returns the first index that has the max value. But, how can I detect that there is a "3-way tie" going on and have it decide the tie breaker with a custom function (on the condition that there is at least a "3-way tie" occurring?
So, first row: sees that there is a "3-way tie" of 4s. Custom function runs so that it can decide the tie-breaker.
Second row: "4-way tie" same thing happens.
Third row: only "2-way tie" which is less than condition of at least a "3-way tie". Can default to np.argmax
.