Skip to content

Instantly share code, notes, and snippets.

@moraisaugusto
Created April 17, 2019 09:15
Show Gist options
  • Save moraisaugusto/7b6a412e7c9ef54502e639f46d910d53 to your computer and use it in GitHub Desktop.
Save moraisaugusto/7b6a412e7c9ef54502e639f46d910d53 to your computer and use it in GitHub Desktop.
Prevent np zero division
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