可见的弃用警告......? [英] Visible Deprecation warning...?

查看:41
本文介绍了可见的弃用警告......?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据从 h5 文件中读取为一个 numpy 数组,并且正在做一些分析.对于上下文,数据绘制了光谱响应曲线.我正在索引数据(以及我为 x 轴制作的后续数组)以获得特定值或值范围.我没有做任何复杂的事情,即使是我正在做的小数学也是非常基本的.但是我在很多地方收到以下警告错误

I have some data that Im reading from a h5 file as a numpy array and am doing some analysis with. For context, the data plots a spectral response curve. I am indexing the data (and a subsequent array I have made for my x axis) to get a specific value or range of values. Im not doing anything complex and even the little maths I'm doing is pretty basic. However I get the following warning error in a number of places

VisibleDeprecationWarning:布尔索引与维度 0 的索引数组不匹配;维度为 44,但对应的布尔维度为 17"

"VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 44 but corresponding boolean dimension is 17"

即使我在检查时得到的输出是正确的.

even though the output I get is the correct one when I check it.

有人能解释一下这个警告是什么意思,我是否需要比现在更关心它?

Can someone explain what this warning means and whether I need to be more concerned about it than I currently am?

我不确定示例代码是否会对此有所说明,但鉴于这是我索引和切片数组时发生的警告,无论如何这里有一些:

Im not sure example code would shed much light on this, but seeing as it is a warning that occurs when I index and slice arrays, here is some 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]

推荐答案

之前关于此警告的问题:

Previous questions on this warning:

VisibleDeprecationWarning:布尔索引与索引数组不匹配沿维度 1;维度是 2 但对应的布尔维度是 1

https://stackoverflow.com/a/34296620/901925

我认为这是 numpy 1.10 中的新东西,是使用比数组短的布尔索引的结果.我没有安装那个版本,所以不能举个例子.但是在更早的 numpy

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]: ind
Out[669]: array([ True, False, False,  True], dtype=bool)
In [670]: x[ind]
Out[670]: array([0, 3])

运行正常,即使 indx 短.它有效地用 False 填充 ind.我认为较新的版本会继续进行计算,但会发出此警告.我需要找到一个改变这个的提交或一个讨论它的 SO 问题.

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 讨论

https://github.com/numpy/numpy/issues/4980 布尔值数组索引无声无息地失败 #4980

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

拉取请求

https://github.com/numpy/numpy/pull/4353 DEP: 弃用形状不匹配的布尔数组索引 #4353

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 warnings
warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning) 

您可能需要调整类别名称以使其正确.

you may have to tweak the category name to get it right.

这篇关于可见的弃用警告......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆