-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Remove/rework uses of np.where where possible. #13385
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
Conversation
@@ -43,27 +43,19 @@ def __str__(self): | |||
self._apply_theta_transforms)) | |||
|
|||
def transform_non_affine(self, tr): | |||
xy = np.empty(tr.shape, float) | |||
|
|||
t = tr[:, 0:1] |
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 slice makes t
2D; I don't remember why that was important though.
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.
I know, but staring at the code it seems unlikely to matter (it's been like that ever since polar.py appeared in 2008, so probably just "historical").
e629ee1
to
09467ce
Compare
@@ -18,7 +17,7 @@ | |||
s2 = 2 * np.sin(2 * np.pi * 400 * t) | |||
|
|||
# create a transient "chirp" | |||
mask = np.where(np.logical_and(t > 10, t < 12), 1.0, 0.0) | |||
mask = (10 < t) & (t < 12) | |||
s2 = s2 * mask |
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.
I think I'd rather write this as:
s2[t <= 10] = 0
s2[12 <= t] = 0
(or using an or)
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.
good catch, fixed (and rebased)
Seems to need a rebase though. |
In a few places, np.where can be replaced by direct use of boolean arrays, or other constructs. In colors.py, the use of putmask may be slightly obscure (so I left a comment explaining it), but avoids repeating the modified array twice, so I think is more legible. In polar.py, preallocating xy is just pointless given that we're constructing intermediate arrays for x and y and filling them into xy afterwards.
In a few places, np.where can be replaced by direct use of boolean
arrays, or other constructs.
In colors.py, the use of putmask may be slightly obscure (so I left a
comment explaining it), but avoids repeating the modified array twice,
so I think is more legible.
In polar.py, preallocating xy is just pointless given that we're
constructing intermediate arrays for x and y and filling them into xy
afterwards.
PR Summary
PR Checklist