In Numpy 1.8, it nansumwas defined as:
a, mask = _replace_nan(a, 0)
if mask is None:
return np.sum(a, axis=axis, dtype=dtype, out=out, keepdims=keepdims)
mask = np.all(mask, axis=axis, keepdims=keepdims)
tot = np.sum(a, axis=axis, dtype=dtype, out=out, keepdims=keepdims)
if np.any(mask):
tot = _copyto(tot, np.nan, mask)
warnings.warn("In Numpy 1.9 the sum along empty slices will be zero.",
FutureWarning)
return tot
In Numpy 1.9, this is:
a, mask = _replace_nan(a, 0)
return np.sum(a, axis=axis, dtype=dtype, out=out, keepdims=keepdims)
I don’t think there is a way to make the new one nansumbehave the same way, but considering that the source code is nansumnot so long, can you just include a copy of this code (without warning) if you care about keeping the behavior up to 1.8.
Please note that _copytoyou can importnumpy.lib.nanfunctions
source
share