I am using numpy.where
, and I was wondering if there was a simply way to avoid calling the unused parameter. Example:
import numpy as np
z = np.array([-2, -1, 0, 1, -2])
np.where(z!=0, 1/z, 1)
returns:
array([-0.5, -1. , 1. , 1. , -0.5])
but I get a divide by zero warning because when z
was 0, the code still evaluates 1/z
even though it doesn't use it.