In numpy I can do the following to avoid division by zero:
a = np.random.randint(0, 10, 100)
b = np.random.randint(0, 10, 100)
c = np.zeros_like(a, dtype=np.float32) # It can be anything other than zero
c = np.divide(a, b, out=c, where=(b!=0))

In torch.divide there is no where argument for masking. Only way seems to be replacing inf with desired value after the division takes place. Is there any better way to do this in pytorch?