-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Add keepdims
argument to argmin and argmax
#8710
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
Comments
This might actually be done best by making |
Trivial implementation: def argmin(*args, keepdims=False, **kwargs):
res = np.argmin(*args, **kwargs)
axis = kwargs.get('axis', none)
if axis is not None:
res = np.expand_dims(res, axis=axis)
return res |
The challenge here is that only |
The next problem is that |
I would be glad about this features. As I was thinking of trying to contribute to numpy for some time, would somebody mind if I simply tried to implement the feature according to the development workflow? |
Folks, below is the workaround I'm currently using. Please reply if you see a better way to preserve original dimensions. Thanks. def argmax_keepdims(x, axis):
"""
Returns the indices of the maximum values along an axis.
The axis which is reduced is left in the result as dimension with size one.
The result will broadcast correctly against the input array.
Original numpy.argmax() implementation does not currently support the keepdims parameter.
See https://github.com/numpy/numpy/issues/8710 for further information.
"""
output_shape = list(x.shape)
output_shape[axis] = 1
return np.argmax(x, axis=axis).reshape(output_shape) |
In my case |
For consistency with
min
andmax
, so that the returned object is the same shape.The text was updated successfully, but these errors were encountered: