np.MaskedArray.transpose() produces partial views
See original GitHub issue>>> src = np.ma.masked_where([0, 1, 0], [1, 1337, 1])
>>> dst = np.ma.masked_where([1, 0, 0, 0, 0], np.zeros(5))
>>> dst_view = dst.transpose()
# check the views look ok
>>> dst
masked_array(data = [-- 0 0 0 0],
mask = [ True False False False False],
fill_value = 999999)
>>> dst_view
masked_array(data = [-- 0 0 0 0],
mask = [ True False False False False],
fill_value = 999999)
# now write a slice of the view
>>> dst_view[2:5] = src
>>> dst_view
masked_array(data = [-- 0 1 -- 1],
mask = [ True False False True False],
fill_value = 999999)
# but looking back at the original, the data was updated but the mask was not!
>>> dst
masked_array(data = [-- 0 1 1337 1],
mask = [ True False False False False],
fill_value = 999999)
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
numpy.ma.MaskedArray.transpose — NumPy v1.24 Manual
Returns a view of the array with axes transposed. Refer to numpy.transpose for full documentation. Parameters: axesNone, tuple of ints ...
Read more >NumPy Reference
NumPy provides an N-dimensional array type, the ndarray, which describes a collection of “items” of the same type.
Read more >How does NumPy's transpose() method permute the axes ...
To transpose an array, NumPy just swaps the shape and stride information for each axis. Here are the strides: >>> arr.strides (64, 32, ......
Read more >Fluent NumPy. Let's uncover the practical details of…
The view() method creates a new array object that looks at the same data. Slicing an array returns a view of it.
Read more >Guide to NumPy
ndarray can always produce an ndarray object without copying any data. This is sometimes referred to as the “view” feature of array indexing ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This behaviour is as intended originally (see masked array docs), but it is not obvious it is a good idea (see #5558), and hence plans are afoot to change it: #5580. The latter PR is also the reason you are getting
FutureWarning
. One thing that might be useful for #5580 is to check that your examples would work with that PR (in particular for the transpose, for which you do not get theFutureWarning
).I am not sure, but it might be possible to set
_sharedmask
to true. However, it may not actually warn in all cases that will change, but only for assignments.