How to return 0 with divide by zero
In numpy v1.7+, you can take advantage of the “where” option for ufuncs. You can do things in one line and you don’t have to deal with the errstate context manager. >>> a = np.array([-1, 0, 1, 2, 3], dtype=float) >>> b = np.array([ 0, 0, 0, 2, 2], dtype=float) # If you don’t pass … Read more