why is numpy where keep raising divide by zero encountered?
100/np.sqrt(w) still uses the w with zeros because function arguments are evaluated before executing a function. The square root of zero is zero, so you end up dividing 100 by an array that contains zeros, which in turn attempts to divide 100 by each element of this array and at some point tries to divide it by an element that's equal to zero.
I have an array like w=[0.854,0,0.66,0.245,0,0,0,0] and want to apply 100/sqrt(x) on each value. As I can't divide by 0, I'm using this trick :
w=np.where(w==0,0,100/np.sqrt(w))
As I'm not dividing by 0, I shouldn't have any warning.
So why does numpy keep raising RuntimeWarning: divide by zero encountered in true_divide ?