I have a list L
and I want to compute for each elementconst/L_j
and get a new list M
with elements M_j = const/L_j
. However, there are L_j
elements that are zero. In this case it is preferred to assign such division to zero. I have made this the script below but it is slow.
temp = np.zeros((self.n_features, 1))
for t in range(self.n_features):
if y[t]!=0:
temp[t] = x/y[t]
My question is similar to this but I want to apply it in a list. Is these a faster way to compute list M
.
Thanks.