python - How to handle ZeroDivisionError inside numpy array -
i have 2 big numpy arrays, need divide them.
since working on python 32-bits, , arrays big, avoid floatingpointerror
, doing, example:
x = numpy.array([...],dtype=object) y = numpy.array([...].dtype=object)
the problem that, inside array y
, elements can 0.0
so, question, how handle calculation x/y
, avoid zerodivisionerror
.
for exmaple, force nan
if element in y
0. that, particular element inside array, calculation x/y=nan
use masked arrays,
x = numpy.array([...],dtype=object) y = numpy.array([...].dtype=object) x_m = numpy.ma.array(x, mask=~(x==0)) y_m = numpy.ma.array(y, mask=~(y==0)) print(x_m/y_m)
Comments
Post a Comment