Numpy 1.13 MaskedArrayFutureWarning: setting a masked array element that has a common mask will not copy the mask

I recently upgraded from numpy 1.11 to numpy 1.13, hoping to get rid of this warning in a mask, but it's still there:

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.*

Basically my code just changes some masked masked values, and I'm not sure what this error even means.

I was hoping that upgrading to numpy 1.13 would resolve this, but I think the error is at my end.

For clarity, I run numpy 1.13, despite the warning referencing 1.11:

Python 2.7.12 (default, November 19, 2016 06:48:10)

[GCC 5.4.0 20160609] on linux2

Enter “help,” “copyright,” “credits,” or “license” for more information.

import numpy as np

np version

'1.13.0.dev0 + Unknown'

. Cat

+4
1

.

:

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

data

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)

data, .

:

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.

: ​​ x y ( )? ?

=================

, , :

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). , .

future:

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.

+7

Source: https://habr.com/ru/post/1663170/


All Articles