Visible failure warning ...?

I have some data Im reading from a h5 file as a numpy array and doing some analysis. For context, the data show a spectral response curve. I index the data (and the subsequent array that I made for the x axis) to get a specific value or range of values. I do not do anything complicated and even the little math that I do is pretty simple. However, I get the following warning error in several places

"VisibleDeprecationWarning: boolean index does not match the indexed array along dimension 0, the dimension is 44, but the corresponding Boolean dimension is 17"

although the conclusion I get is correct when I test it.

Can someone explain what this warning means, and do I need to worry more about it than I do now?

I'm not sure if the sample code sheds much light on this, but seeing that this is a warning that occurs when I index arrays of slices, anyway:

data = h5py.File(file,'r') dset = data['/DATA/DATA/'][:] vals1 = dset[0] AVIRIS = numpy.linspace(346.2995778, 2505.0363678, 432) AVIRIS1 = AVIRIS[vals1>0] AVIRIS1 = AVIRIS[vals1<1] 
+6
source share
2 answers

Previous questions about this warning:

VisibleDeprecationWarning: boolean index does not match an indexed array of size 1; the dimension is 2, but the corresponding Boolean dimension is 1

fooobar.com/questions/1001784 / ...

I think this is something new in numpy 1.10 and is the result of using a logical index that is shorter than an array. I do not have an installed version, so I can not give an example. But in earlier numpy

 In [667]: x=np.arange(10) In [668]: ind=np.array([1,0,0,1],bool) In [669]: ind Out[669]: array([ True, False, False, True], dtype=bool) In [670]: x[ind] Out[670]: array([0, 3]) 

works fine even though ind shorter than x . It efficiently pads ind using False . I think new versions continue to do the calculations, but they give this warning. I need to find a commit that changed this question or an SO question that discusses it.

You can suppress warnings - see the sidebar. But you really have to check the shape of the offending arrays. Do they match, or is the Boolean index too? Can you fix it?

Github talk

https://github.com/numpy/numpy/issues/4980 Boolean array indexing fails # 4980

Request Request

https://github.com/numpy/numpy/pull/4353 DEP: obsolete logical array indices with inconsistent form # 4353

To suppress a warning, use something like:

 import warnings warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning) 

you may need to adjust the category name to be correct.

+9
source

To suppress a warning, you can:

  • (evil)

add something like this to your .bashrc or, if you set environment variables, to turn off visible failure warnings globally:

export PYTHONWARNINGS="ignore::DeprecationWarning:simplejson"

  1. (bad)

Turning alerts when running a single script:

python -W ignore thisbetterworks.py

  1. (okayish)

Run the block without warning:

import warnings with warnings.catch_warnings(): warnings.warn("Let this be your last warning") warnings.simplefilter("ignore") < your code >

Of course, you risk that this will happen when fatigue turns into an absence, so you might want to make sure that it does not end with a long-term code.

+2
source

All Articles