Created
April 17, 2019 09:15
-
-
Save moraisaugusto/7b6a412e7c9ef54502e639f46d910d53 to your computer and use it in GitHub Desktop.
Prevent np zero division
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
x = np.array([[2., 54, 2., 5, 2], | |
[2, 0, 0.02, 0.00005, 0.0]]) | |
y = [2, 0, 0.02, 0.00005, 0.0] | |
print(np.where(x[0] > 1e-3, x[0]/(x[1]+(x[1]==0)), 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment