Visible Deprecation warning...?
Previous questions on this warning:
https://stackoverflow.com/a/34296620/901925
I think this is something new in numpy 1.10, and is the result of using boolean index that is shorter than array. I don't have that version installed so can't give an example. But in an earlier numpy
In [667]: x=np.arange(10)In [668]: ind=np.array([1,0,0,1],bool)In [669]: indOut[669]: array([ True, False, False, True], dtype=bool)In [670]: x[ind]Out[670]: array([0, 3])
runs ok, even though ind
is shorter than x
. It effectively pads ind
with False
. I think newer versions continue to do the calculation, but issue this warning. I need to find a commit that changed this or a SO question that discusses it.
It is possible to suppress warnings - see the side bar. But you really should check the shape of the offending arrays. Do they match, or is the boolean index too short? Can you correct that?
Github discussion
https://github.com/numpy/numpy/issues/4980 Boolean array indexing fails silently #4980
Pull request
https://github.com/numpy/numpy/pull/4353 DEP: Deprecate boolean array indices with non-matching shape #4353
To suppress the warning use something like:
import warningswarnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning)
you may have to tweak the category name to get it right.
To suppress the warning you can:
- (evil)
add something like this to your .bashrc
or whereever you set environmental variables to turn off visible deprecation warnings globally:
export PYTHONWARNINGS="ignore::DeprecationWarning:simplejson"
- (bad)
Turn of warnings when running a single script:
python -W ignore thisbetterworks.py
- (okayish)
Run a block without warnings:
import warningswith warnings.catch_warnings(): warnings.warn("Let this be your last warning") warnings.simplefilter("ignore") < your code >
Of course you do run the risk of this failing when deprecation turns to absence, so you may want to make sure it doesn't end up in long-term code.