Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Replace np.take by normal indexing. #13383

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

Merged
merged 1 commit into from
Feb 8, 2019
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Feb 7, 2019

np.take(x, ind) is equivalent to x.ravel()[ind] and np.take(x, ind, axis=0) to x[ind] (except for some details about contiguity of the
output, not relevant to the changes here). Straight indexing is more
legible, so use that.

In pick_event_demo, additionally replace zip() by column_stack(), as,
on Py3, printing a zip() object results in <zip object at 0xdeadbeef>
which is clearly not intended in the example.

In the same example, np.nonzero() always returns a 1-tuple (for 1d
inputs), so the if len(ind) test always returned True and the picker
would incorrectly fire even when clicking far away from the plotted
points. Fix that by unpacking the 1-tuple.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

`np.take(x, ind)` is equivalent to `x.ravel()[ind]` and `np.take(x, ind,
axis=0)` to `x[ind]` (except for some details about contiguity of the
output, not relevant to the changes here -- there are other places that
do rely on the contiguity).  Straight indexing is more legible, so use
that.

In pick_event_demo, additionally replace zip() by column_stack(), as,
on Py3, printing a zip() object results in `<zip object at 0xdeadbeef>`
which is clearly not intended in the example.

In the same example, `np.nonzero()` always returns a 1-tuple (for 1d
inputs), so the `if len(ind)` test always returned True and the picker
would incorrectly fire even when clicking far away from the plotted
points.  Fix that by unpacking the 1-tuple.
@QuLogic QuLogic added this to the v3.1.0 milestone Feb 8, 2019
@QuLogic QuLogic merged commit 3040b90 into matplotlib:master Feb 8, 2019
@anntzer anntzer deleted the untake branch February 8, 2019 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.