question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mhvkcommented, Jan 20, 2017

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 the FutureWarning).

0reactions
sebergcommented, Jan 21, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found