<div dir="ltr">On Thu, Mar 12, 2015 at 1:31 PM, Johannes Kulick <<a href="mailto:johannes.kulick@ipvs.uni-stuttgart.de">johannes.kulick@ipvs.uni-stuttgart.de</a>> wrote:<br>><br>> Hello,<br>><br>> I wonder if it would be worth to enhance max, min, argmax and argmin (more?)<br>> with a tie breaking parameter: If multiple entries have the same value the first<br>> value is returned by now. It would be useful to have a parameter to alter this<br>> behavior to an arbitrary tie-breaking. I would propose, that the tie-breaking<br>> function gets a list with all indices of the max/mins.<br>><br>> Example:<br>> >>> a = np.array([ 1, 2, 5, 5, 2, 1])<br>> >>> np.argmax(a, tie_breaking=random.choice)<br>> 3<br>><br>> >>> np.argmax(a, tie_breaking=random.choice)<br>> 2<br>><br>> >>> np.argmax(a, tie_breaking=random.choice)<br>> 2<br>><br>> >>> np.argmax(a, tie_breaking=random.choice)<br>> 2<br>><br>> >>> np.argmax(a, tie_breaking=random.choice)<br>> 3<br>><br>> Especially for some randomized experiments it is necessary that not always the<br>> first maximum is returned, but a random optimum. Thus I end up writing these<br>> things over and over again.<br>><br>> I understand, that max and min are crucial functions, which shouldn't be slowed<br>> down by the proposed changes. Adding new functions instead of altering the<br>> existing ones would be a good option.<br>><br>> Are there any concerns against me implementing these things and sending a pull<br>> request? Should such a function better be included in scipy for example?<br><br>On the whole, I think I would prefer new functions for this. I assume you only need variants for argmin() and argmax() and not min() and max(), since all of the tied values for the latter two would be identical, so returning the first one is just as good as any other.<div><br>--<br>Robert Kern</div></div>