[Numpy-discussion] nan division warnings
mdekauwe
mdekauwe@gmail....
Tue Aug 30 22:39:36 CDT 2011
Hi,
this is probably my lack of understanding...when i set up some masks for 2
arrays and try to divide one by the other I get a runtime warning. Seemingly
this is when I am asking python to divide one nan by the other, however I
thought by masking the array numpy would then know to ignore these nans? For
example
import numpy as np
a = np.array([4.5, 6.7, 8.0, 9.0, 0.00001])
b = np.array([0.0001, 6.7, 8.0, 9.0, 0.00001])
a = np.ma.where(np.logical_or(a<0.01, b<0.01), np.nan, a)
b = np.ma.where(np.logical_or(a<0.01, b<0.01), np.nan, b)
a/b
will produce
…./numpy/ma/core.py:772: RuntimeWarning: invalid value encountered in
absolute
return umath.absolute(a) * self.tolerance >= umath.absolute(b)
but of course give the correct result
masked_array(data = [-- 1.0 1.0 1.0 --],
mask = [ True False False False True],
fill_value = 1e+20)
But what is the correct way to do this array division such that I don't
produce the warning? The only way I can see that you can do it is a bit
convoluted and involves empty the array of the masked values, e.g.
a = a[np.isnan(a) == False]
b = b[np.isnan(b) == False]
a/b
thanks,
Martin
--
View this message in context: http://old.nabble.com/nan-division-warnings-tp32369310p32369310.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.
More information about the NumPy-Discussion
mailing list