Skip to content

Conversation

danra
Copy link
Contributor

@danra danra commented Apr 25, 2025

No description provided.

@@ -1306,6 +1306,8 @@ def argmax(a, axis=None, out=None, *, keepdims=np._NoValue):

Indexes of the maximal elements of a N-dimensional array:

>>> a.flat[np.argmax(a)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a useful addition to the docs, but the example code does not match the text above (e.g. Indexes of the maximal elements of a N-dimensional array:). Maybe move this a bit down (after the a[ind] example)? Or rename the text to Indices and values of the maximal ...

Note: both Indexes and Indices are correct, but it is a bit inconsistent to have the docs of argmin and argmax use a different form.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to me like it could be a separate change. The addition just shows how to simply use the index without having to unravel it first; the raw form is used to actually to get the value, but that was already the case with the unraveled form. (and unlike the unraveled form, the raw index already appears above, so seemed to me like it's not worth repeating).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition just shows how to simply use the index without having to unravel it first

The point of the section that starts with "Indexes of the maximal elements of a N-dimensional array:" is to show how to obtain the indices of the maximal elements when using axis=None. Is your addition relevant to that section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Just like existing first example it precedes in each of argmin/argmax shows how to obtain and take the value at an index by using unravel_index, this one shows how to do it by using flat.

@charris charris changed the title DOC: Add flat examples to argmax and armgin DOC: Add flat examples to argmax and argmin May 10, 2025
@melissawm melissawm moved this to Needs decision in NumPy first-time contributor PRs May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs decision
Development

Successfully merging this pull request may close these issues.

3 participants