I have a two-dimensional numpy array of data, holding symmetric information about pairs of elements I'm tracking, very much like a round-robin bracket in a tournament. Keeping with that analogy, each player occupies one row with the column data being their score against a given opponent. For "legacy" reasons, all scores will be positive numbers except for the score against oneself, which will be 0.
Let's say I want to find the worst score of a given player, returning both the score and the opponent they played for that score. How might I do this?
The mediocre version might look like:
minimum = float('inf')
min_opp = None
for opponent_id in player_ids:
if opponent_id != player_id:
score = match_matrix[player_id, opponent_id]
if score < minimum:
minimum = score
min_opp = opponent_id
return minimum, min_opp
But that's not using the power of numpy at all. I feel like there should be an easy solution, but I cannot seem to find it.
score = np.min(match_matrix[player, :])
gives the self-score, and I can't quite make the code from this answer work correctly.
Thanks!
EDIT: This answer provides good ideas, but only gets the minimum of the entire array, not a single row.