I occasionally use the where
clause in numpy's ufuncs. For example, the following:
import numpy as np
a = np.linspace(-1, 1, 10)
np.sqrt(a, where=a>0) * (a>0)
In Numpy 1.12 and earlier, this used to give me square root values where possible and zero otherwise.
Recently, though, I upgraded to numpy 1.13. The code above now gives me the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Automatic allocation was requested for an iterator operand, and it was flagged as readable, but buffering without delayed allocation was enabled
I thought that this was exactly how the where
clause was supposed to be used, but perhaps I was wrong. So I have two questions: first, what's wrong with this code; and second, what is the recommended way of achieving my goal?