def my_argmax(a): rows = np.where(a == a.max(axis=1)[:, None])[0] rows_multiple_max = rows[:-1][rows[:-1] == rows[1:]] my_argmax = a.argmax(axis=1) my_argmax[rows_multiple_max] = -1 return my_argmax