[Numpy-discussion] Re: np.where and ZeroDivisionError: float division by zero

2024-04-26 Thread Lucas Colley
> What you are hoping for here is known as "short circuit" or "lazy" evaluation. In SciPy, we have the private utility function `_lazywhere`[1] for this. Cheers, Lucas [1] https://github.com/scipy/scipy/blob/f44326023dc51758495491fc9f06858fd38358a0/scipy/_lib/_util.py#L88-L156 > On 26 Apr 2024

[Numpy-discussion] Re: np.where and ZeroDivisionError: float division by zero

2024-04-26 Thread rosko37
What you are hoping for here is known as "short circuit" or "lazy" evaluation. Namely, this would work if np.where(cond, x, y) only evaluates x if cond is true and only evaluates y if cond is false. In this case, not only can it handle situations where one of the true/false cases "breaks" one of th

[Numpy-discussion] Re: np.where and ZeroDivisionError: float division by zero

2024-04-25 Thread Fang Zhang
The function np.where just chooses elements from two arrays that are both computed before np.where is even executed. See this StackOverflow answer https://stackoverflow.com/a/29950752/4681187 if you want to suppress the error. On Thu, Apr 25, 2024 at 8:16 PM 840362492--- via NumPy-Discussion < num