Skip to content
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

Correcting solution to the 'round away from 0' exercise #17

Merged
merged 1 commit into from
Aug 23, 2016

Conversation

ibah
Copy link
Contributor

@ibah ibah commented Aug 23, 2016

Exercise: How to round away from zero a float array?
Problem:
Z = np.array([1.4])
np.trunc(Z + np.copysign(0.5, Z)) # prints 1. instead of 2.
Z = np.array([1.0])
np.round(Z + np.copysign(0.5, Z)) # prints 2. instead of 1.
Solution:
Z = np.array([1.0, 1.4])
np.copysign(np.ceil(np.abs(Z)), Z) # prints correct [1., 2.]

@rougier
Copy link
Owner

rougier commented Aug 23, 2016

Thanks

@rougier rougier merged commit 9ee1a2c into rougier:master Aug 23, 2016
@rougier
Copy link
Owner

rougier commented Aug 31, 2016

I've cancelled the PR (see issue #19)

gfabj added a commit to gfabj/numpy-100 that referenced this pull request Jun 2, 2017
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.

None yet

2 participants