UPDATE (real error)
I incorrectly identified where the error came from. Here is my whole function (sorry if some of the lines are unclear and confusing ...)
def removeLines(input,CRVAL1,CDELT1):
I investigated the problem and found the answer that is posted below (not in this post).
Error (stupid false error)
made a conclusion
left = 1333 right = 1490 20 from right = [ 0.14138737 0.14085886 0.14038289 0.14045525 0.14078836 0.14083192 0.14072289 0.14082283 0.14058594 0.13977806 0.13955595 0.13998236 0.1400764 0.1399636 0.14025062 0.14074247 0.14094831 0.14078569 0.14001536 0.13895717] mean of 20 = 0.140395 Traceback (most recent call last): ... File "getRVs.py", line 201, in removeLines right_avg = numpy.mean(input[right:right+20]) File "C:\Users\MyName\Anaconda\lib\site-packages\numpy\core\fromnumeric.py", line 2735, in mean out=out, keepdims=keepdims) File "C:\Users\MyName\Anaconda\lib\site-packages\numpy\core\_methods.py", line 59, in _mean warnings.warn("Mean of empty slice.", RuntimeWarning) RuntimeWarning: Mean of empty slice.
It seems that numpy.mean works correctly when I print it, but differently when I assign it a value. Any feedback would be greatly appreciated. Thanks for taking the time to read my question.
Short description
In short, I am writing code to process scientific data, and part of the code involves taking a value of about 20 values.
This code returns numpy "Mean empty slice". warning and annoyingly prints it in my precious product! For example, I decided to try to track the source of the warning, for example, here , so I posted
import warnings warnings.simplefilter("error")
at the top of my code, which then returned the following traceback cut off:
File "getRVs.py", line 201, in removeLines right_avg = numpy.mean(input[right:right+20]) File "C:\Users\MyName\Anaconda\lib\site-packages\numpy\core\fromnumeric.py", line 2735, in mean out=out, keepdims=keepdims) File "C:\Users\MyName\Anaconda\lib\site-packages\numpy\core\_methods.py", line 59, in _mean warnings.warn("Mean of empty slice.", RuntimeWarning) RuntimeWarning: Mean of empty slice.
I missed about 2/3 of Traceback because it moves through about 5 complex functions that do not affect the readability or size of the data.
So, I decided to print out the whole operation to see if right_avg is right_avg trying to numpy.mean empty slice ... And this is when everything gets really weird.