0

I want to make divisioin between two ndarrays and if there is a zero at one index of divisor, at the same index of result, there should be a zero. Is there any way to do it elegantly rather than using for loop to check every elements?

normal = np.empty(grad.shape, dtype=arrOrg.dtype)
for i in range(3):
  normal[i] = grad[i]/mod

If I just do so, there would be a warning: RuntimeWarning: invalid value encountered in true_divide

Raykie
  • 31
  • 5
  • dividing by zero will give ```np.inf```. You can either suppress this conversion temporarily or set them manually to zero by doing ```normal[np.isinf(normal)]=0```. – Kevin Apr 21 '21 at 12:12
  • 2
    See the accepted answer in [How to return 0 with divide by zero](https://stackoverflow.com/questions/26248654/how-to-return-0-with-divide-by-zero). – Nikolaos Chatzis Apr 21 '21 at 12:17

0 Answers0