Fix Python – How to return 0 with divide by zero

I’m trying to perform an element wise divide in python, but if a zero is encountered, I need the quotient to just be zero.
For example:
array1 = np.array([0, 1, 2])
array2 = np.array([0, 1, 1])

array1 / array2 # should be np.array([0, 1, 2])

I could always just use a for-loop through my data, but to really utilize numpy’s optimizations, I need t….

Fix Python – How do I catch a numpy warning like it’s an exception (not just for testing)?

I have to make a Lagrange polynomial in Python for a project I’m doing. I’m doing a barycentric style one to avoid using an explicit for-loop as opposed to a Newton’s divided difference style one. The problem I have is that I need to catch a division by zero, but Python (or maybe numpy) just makes it a warning instead of a normal exception.
So, wh….