I\'m getting Mean of empty slice
runtime warnings.
When I print out what my variables are (numpy arrays), several
of them contain nan
values. The Runti
I assume the warning comes up in
np.mean(dataPoints[t2 == [x]], axis=0)
If t2 == [x]
is all False (no match between t2
and x
, then dataPoints[...]
will be an empty array, resulting in the mean
warning.
I think you need to be more careful with that test. Maybe even skip the mean
if the masked array is empty.
==
tests with floating values are unpredictable. You need to use something like np.isclose
or np.allclose
to test equivalence with a tolerance.
The second warning comes from later in the mean
calc, presumably when trying to divide by 0, the number of elements.
The full mean
code can be found in numpy.core._methods.py
.
In sum, don't try to take the mean
of an empty array.