Python numpy 1.13掩码DarrayFutureWarning:在具有共享掩码的掩码数组上设置项不会复制掩码
我最近从numpy 1.11升级到numpy 1.13,希望摆脱这个蒙面阵列警告,但它仍然存在:Python numpy 1.13掩码DarrayFutureWarning:在具有共享掩码的掩码数组上设置项不会复制掩码,python,numpy,mask,Python,Numpy,Mask,我最近从numpy 1.11升级到numpy 1.13,希望摆脱这个蒙面阵列警告,但它仍然存在: MaskedArrayFutureWarning:在具有共享掩码的掩码数组上设置项不会复制掩码,也不会在将来更改原始掩码数组。 有关更多信息,请查看NumPy 1.11发行说明* 基本上,我的代码只是更改了屏蔽数组中的一些值,我甚至不确定这个错误的含义 我本来希望升级到numpy 1.13可以解决这个问题,但我认为错误就在我这边 为了清楚起见,我运行的是numpy 1.13,尽管有参考1.11的警
MaskedArrayFutureWarning:在具有共享掩码的掩码数组上设置项不会复制掩码,也不会在将来更改原始掩码数组。
有关更多信息,请查看NumPy 1.11发行说明*
基本上,我的代码只是更改了屏蔽数组中的一些值,我甚至不确定这个错误的含义
我本来希望升级到numpy 1.13可以解决这个问题,但我认为错误就在我这边
为了清楚起见,我运行的是numpy 1.13,尽管有参考1.11的警告:
Python 2.7.12(默认值,2016年11月19日,06:48:10)
[GCC 5.4.0 20160609]关于linux2
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”
将numpy作为np导入
np.版本
“1.13.0.dev0+未知”
谢谢你的帮助。
Cat这种共享面具业务有点令人困惑 当前行为:
In [150]: x=np.ma.masked_greater(np.arange(8),5)
In [151]: x
Out[151]:
masked_array(data = [0 1 2 3 4 5 -- --],
mask = [False False False False False False True True],
fill_value = 999999)
In [152]: y=x[3:6] # a view
In [153]: y[0]=30 # modify the view
/usr/local/bin/ipython3:1: MaskedArrayFutureWarning: setting an item on a masked array which has a shared mask will not copy the mask and also change the original mask array in the future.
Check the NumPy 1.11 release notes for more information.
#!/usr/bin/python3
In [205]: y=x[4:]
In [206]: y._sharedmask=False
In [207]: y[-1]=0
In [208]: y
Out[208]:
masked_array(data = [4 5 -- 0],
mask = [False False True False],
fill_value = 999999)
In [209]: x
Out[209]:
masked_array(data = [0 1 2 3 4 5 -- 0],
mask = [False False False False False False True False],
fill_value = 999999)
数据
值更改与源共享
In [154]: y
Out[154]:
masked_array(data = [30 4 5],
mask = [False False False],
fill_value = 999999)
In [155]: x
Out[155]:
masked_array(data = [0 1 2 30 4 5 -- --],
mask = [False False False False False False True True],
fill_value = 999999)
但掩码值更改不是:
In [156]: y.mask[0]=True
In [157]: y
Out[157]:
masked_array(data = [-- 4 5],
mask = [ True False False],
fill_value = 999999)
In [158]: x
Out[158]:
masked_array(data = [0 1 2 30 4 5 -- --],
mask = [False False False False False False True True],
fill_value = 999999)
创建新视图,并调用unshare
方法:
In [159]: y=x[3:6]
In [160]: y.unshare_mask()
Out[160]:
masked_array(data = [30 4 5],
mask = [False False False],
fill_value = 999999)
In [161]: y[0]=31
In [162]: y
Out[162]:
masked_array(data = [31 4 5],
mask = [False False False],
fill_value = 999999)
In [163]: x
Out[163]:
masked_array(data = [0 1 2 31 4 5 -- --],
mask = [False False False False False False True True],
fill_value = 999999)
这会更改数据
,而不会发出警告
在没有警告的情况下,可以通过以下方式生成未来行为:
In [172]: x=np.ma.masked_greater(np.arange(8),5)
In [174]: y=x[3:6]
In [175]: y._sharedmask=False
In [176]: y[0]=30
In [177]: y.mask[0]=True
In [178]: y
Out[178]:
masked_array(data = [-- 4 5],
mask = [ True False False],
fill_value = 999999)
In [179]: x
Out[179]:
masked_array(data = [0 1 2 -- 4 5 -- --],
mask = [False False False True False False True True],
fill_value = 999999)
新值和掩码同时出现在y
和x
中
底线是-当您更改y
中的值(数据或掩码)时,x
中的掩码会发生什么情况?是否改变
=================
或者,在视图中设置数据值也会更改遮罩的情况可能更清楚:
In [199]: x=np.ma.masked_greater(np.arange(8),5)
In [200]: y=x[4:]
In [201]: y
Out[201]:
masked_array(data = [4 5 -- --],
mask = [False False True True],
fill_value = 999999)
In [202]: y[-1]=0
/usr/local/bin/ipython3:1: MaskedArrayFutureWarning: setting an item on a masked array which has a shared mask will not copy the mask and also change the original mask array in the future.
Check the NumPy 1.11 release notes for more information.
#!/usr/bin/python3
In [203]: y
Out[203]:
masked_array(data = [4 5 -- 0],
mask = [False False True False],
fill_value = 999999)
In [204]: x
Out[204]:
masked_array(data = [0 1 2 3 4 5 -- --],
mask = [False False False False False False True True],
fill_value = 999999)
最后一个y
值未屏蔽,但相应的x
未屏蔽(我应该显示x.data
的更改)。这是当前警告您的行为
但是对于未来
行为:
In [150]: x=np.ma.masked_greater(np.arange(8),5)
In [151]: x
Out[151]:
masked_array(data = [0 1 2 3 4 5 -- --],
mask = [False False False False False False True True],
fill_value = 999999)
In [152]: y=x[3:6] # a view
In [153]: y[0]=30 # modify the view
/usr/local/bin/ipython3:1: MaskedArrayFutureWarning: setting an item on a masked array which has a shared mask will not copy the mask and also change the original mask array in the future.
Check the NumPy 1.11 release notes for more information.
#!/usr/bin/python3
In [205]: y=x[4:]
In [206]: y._sharedmask=False
In [207]: y[-1]=0
In [208]: y
Out[208]:
masked_array(data = [4 5 -- 0],
mask = [False False True False],
fill_value = 999999)
In [209]: x
Out[209]:
masked_array(data = [0 1 2 3 4 5 -- 0],
mask = [False False False False False False True False],
fill_value = 999999)
x
数据和掩码随y
一起更改您是否研究了此部分:关于此警告的扩展讨论:。我看不到有证据表明它在较新的版本中被更改了。太有用了!真希望这个答案有更多的可见性。。。向上投票!很好的解释。我也对这个警告感到无助——直到现在