[Numpy-discussion] Re: Invalid value encoutered : how to prevent numpy.where to do this?

2023-02-18 Thread David Pine
I agree. The problem can be avoided in a very inelegant way by turning warnings off before calling where() and turning them back on afterward, like this warnings.filterwarnings("ignore", category=RuntimeWarning) result = np.where(x == 0.0, 0.0, 1./data) warnings.filterwarnings("alwa

[Numpy-discussion] Re: Invalid value encoutered : how to prevent numpy.where to do this?

2023-02-18 Thread Hameer Abbasi via NumPy-Discussion
Hi! You can use a context manager: with np.errstate(all=”ignore”): … Best regards, Hameer Abbasi Von meinem iPhone gesendet > Am 18.02.2023 um 16:00 schrieb David Pine : > > I agree. The problem can be avoided in a very inelegant way by turning > warnings off before calling where() and turnin

[Numpy-discussion] Re: Invalid value encoutered : how to prevent numpy.where to do this?

2023-02-18 Thread Evgeni Burovski
FWIW, scipy has a small utility just for this: https://github.com/scipy/scipy/blob/main/scipy/_lib/_util.py#L36 Not to be used in performance critical loops, of course. Cheers, Evgeni сб, 18 февр. 2023 г., 17:02 David Pine : > I agree. The problem can be avoided in a very inelegant way by t