-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
DOC: Add unravel_index examples to np.arg[min|max|sort] #9333
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
Changes from 1 commit
08d8225
364a575
2b514e3
51d0710
cf43db7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -893,6 +893,8 @@ def argsort(a, axis=-1, kind='quicksort', order=None): | |
Indices of the sorted elements of a N-dimensional array: | ||
>>> np.unravel_index(np.argsort(x, axis=None), x.shape) | ||
(array([0, 1, 1, 0]), array([0, 0, 1, 1])) | ||
>>> from np.testing import assert_equal | ||
>>> assert_equal(x[(array([0, 1, 1, 0]), array([0, 0, 1, 1]))], np.sort(x, axis=None)) | ||
>>> list(zip(*np.unravel_index(np.argsort(x, axis=None), x.shape))) | ||
[(0, 0), (1, 0), (1, 1), (0, 1)] | ||
|
||
|
@@ -961,6 +963,7 @@ def argmax(a, axis=None, out=None): | |
Indices of the maximal elements of a N-dimensional array: | ||
>>> np.unravel_index(np.argmax(a, axis=None), a.shape) | ||
(1, 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to show that the result of this can be used to index directly into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For sure, it's committed. Let me know if you like the way I've written it. |
||
>>> np.testing.assert_equal(a[(1, 2)], np.max(a)) | ||
|
||
>>> b = np.arange(6) | ||
>>> b[1] = 5 | ||
|
@@ -1021,6 +1024,7 @@ def argmin(a, axis=None, out=None): | |
Indices of the minimum elements of a N-dimensional array: | ||
>>> np.unravel_index(np.argmin(a, axis=None), a.shape) | ||
(0, 0) | ||
>>> np.testing.assert_equal(a[(0, 0)], np.min(a)) | ||
|
||
>>> b = np.arange(6) | ||
>>> b[4] = 0 | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be clearer as:
Repeating the call to
unravel_index
is obscuring the point, andassert_equal
isn't that useful in docs. (we don't run doctests)