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

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

问题描述

我有一些数据可以从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]

推荐答案

此警告的先前问题:

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])

即使ind短于x

也可以正常运行.它有效地用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天全站免登陆