New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: np.argmax
, np.argmin
, np.take_along_axis
, and np.put_along_axis
should support tuple axis
a la np.max
and np.min
#25623
Comments
What would you propose |
np.argmax
and np.argmin
should support tuple axis
a la np.max
and np.min
np.argmax
, np.argmin
, np.take_along_axis
, and np.put_along_axis
should support tuple axis
a la np.max
and np.min
A tuple of index arrays sounds fine to me, and that's what's proposed at #9283 (comment), right?
Originally posted by @eric-wieser in #9283 (comment) My only desideratum in requesting this is that |
It sounds like your full proposal would require enhancing |
Yes, I've updated the title to reflect this. |
Notably, x = np.array([[0, 1, 2, 3], [4, 5, 6, 7]])
x_argmax = np.argmax(x, axis=1, keepdims=True)
print(x_argmax)
print(x[x_argmax])
# IndexError: index 3 is out of bounds for axis 0 with size 2 x = np.array([[0, 4], [1, 5], [2, 6], [3, 7]])
x_argmax = np.argmax(x, axis=1, keepdims=True)
print(x[x_argmax])
# [[[1 5]]
# [[1 5]]
# [[1 5]]
# [[1 5]]]
print(np.max(x, axis=1, keepdims=True))
# [[4]
# [5]
# [6]
# [7]] x = np.array([[1000, 1], [1000, 1]])
x_argmax = np.argmax(x, axis=0, keepdims=True)
print(x[x_argmax])
# [[[1000 1]
# [1000 1]]]
print(np.max(x, axis=0, keepdims=True))
# [[1000 1]]
x_argmax = np.argmax(x, axis=1, keepdims=True)
print(x[x_argmax])
# [[[1000 1]]
# [[1000 1]]]
print(np.max(x, axis=1, keepdims=True))
# [[1000]
# [1000]] |
Proposed new feature or change:
scipy/scipy#19549 is blocked on having
argmax
support allaxis
arguments thatmax
supports. The specification of tuple argmax is thatnp.take_along_axis(x, np.argmax(x, axis=axis, keepdims=True), axis=axis)
should always equalnp.max(x, axis=axis, keepdims=True)
.See also #25622 and #9283, where @eric-wieser eventually proposes this constraint in #9283 (comment)
The text was updated successfully, but these errors were encountered: