np.copy(masked array) has unexpected behavior
See original GitHub issue…where “unexpected” means I didn’t expect it. This may just be a documentation fix, or maybe I will be scolded for not realizing how np.ma
works, but I don’t think this behavior is appropriate:
In [100]: x = np.ma.ones(5)
In [101]: x.mask = [False,False,True,False,False]
In [102]: np.copy(x)
Out[102]: array([ 1., 1., 1., 1., 1.])
In [103]: np.ma.copy(x)
Out[103]:
masked_array(data = [1.0 1.0 -- 1.0 1.0],
mask = [False False True False False],
fill_value = 1e+20)
In [104]: np.__version__
Out[104]: '1.8.0.dev-074a40c'
I would at least expect a warning, but would prefer to see, in order of preference:
np.copy(x)
returns a masked array (since x is a masked array)np.copy(x)
warns that it is unmasking the array, then returns the same array as abovenp.copy(x)
raises an exceptionnp.copy(x)
returns[1,1,nan,1,1]
(this is probably not ideal)
Issue Analytics
- State:
- Created 10 years ago
- Reactions:2
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Unexpected numpy.unique behavior - python - Stack Overflow
I am using numpy.unique to get values, indices and counts on a masked array that has been flattened with numpy.ravel and am getting...
Read more >Unexpected behavior of trapz with MaskedArray #9735 - GitHub
I initially expected the numpy.trapz of a MaskedArray to behave as if trapz ... because only the first two values have contiguous elements, ......
Read more >Source code for numpy.ma.core - Astropy
numpy.ma : a package to handle missing or invalid values. This package was initially written for numarray by Paul F. Dubois at Lawrence...
Read more >ak.copy — Awkward Array documentation - Read the Docs
Returns a deep copy of the array (no memory shared with original). This is identical to np.copy and copy.deepcopy . It's only useful...
Read more >1.4.1. The NumPy array object - Scipy Lecture Notes
What are NumPy and NumPy arrays? Creating arrays; Basic data types; Basic visualization; Indexing and slicing; Copies and views; Fancy 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
I’ll send an email to the list on the topic tomorrow.
Created PR #6509 which adds a subok parameter to the function with a default value of False. I’m guessing this will open up some discussion on the topic. Not sure if this typically takes place on the PR, the issue, or the mailing list.