Control "Mean of empty slice" RunTimeWarning with np.errstate
See original GitHub issueAs there already exists a mechanism in numpy to manage warnings for possibly anomalous inputs, it seems odd that it doesn’t work for all warnings. For example, nanmean
raises a warning if given a slice of all nan, and apparently the only way to silence it is to catch it with the python warnings mechanism. np.errstate
, despite claiming to handle divide by zero errors, does not:
Python 3.6.2
In [1]: import numpy as np
In [2]: np.__version__
Out[2]: '1.13.1'
In [3]: allnan = np.array([np.nan, np.nan])
In [4]: with np.errstate(divide='ignore', invalid='ignore'):
...: print(np.nanmean(allnan))
...:
/Users/jonathanshor/anaconda2/envs/Python3/bin/ipython:2: RuntimeWarning: Mean of empty slice
if __name__ == '__main__':
nan
I would suggest this could fall under the divide case, but invalid seems plausible as well.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:7 (4 by maintainers)
Top Results From Across the Web
mean, nanmean and warning: Mean of empty slice
I have got this runtime warning when I perform np.nanmean over a 3-D array, e.g. (time, lon, lat). Maybe not a direct answer...
Read more >[Solved] NumPy RuntimeWarning: Mean of empty slice
The reason this warning arises is because you apply the np.nanmean() function on an empty array. The function doesn't cause an error if...
Read more >Numpy - mbedded.ninja
Numpy prints a warning stating that you are trying to calculate a mean of an empty slice, as well as that there is...
Read more >Source code for tombo.tombo_stats
Empty : break if slide_span > 0: row_dists = np.array( ... base start positions within raw signal Returns: `np.array::np.float64` containing base mean levels ......
Read more >warnings.warn("Mean of empty slice.", RuntimeWarning)
Hi, I am new to qiime and trying to demultiplex a set of reads from 9 different samples. If I use split_libraries_fastq.py -i ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Would this need anything more than a
And then replacing those RuntimeWarnings in the rest of https://github.com/numpy/numpy/blob/v1.15.0/numpy/lib/nanfunctions.py ? Because if that’s all that would be required, I can submit a PR.
That’s an excellent suggestion. Maybe “AllNanAxisWarning” or something similar.