Skip to content
Advertisement

Tag: divide-by-zero

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: I could always just use a for-loop through my data, but to really utilize numpy’s optimizations, I need the divide function to return 0 upon divide by zero errors instead of ignoring the error.

Advertisement