Augmented assignments between unmasked and masked arrays
See original GitHub issueI’m seeing slightly different and unexpected behavior with unmasked and masked arrays in augmented assignments.
For example, the result of masked += unmasked is expected:
import numpy as np
def ab():
return np.array([1, 1]), np.ma.array([5, 5], mask=[False, True])
a, b = ab()
print('a: {0}; b: {1}; b.data: {2}'.format(a, b, b.data))
# a: [1 1]; b: [5 --]; b.data: [5 5]
b += a
print('b: {0}; b.data: {1}'.format(b, b.data))
# b: [6 --]; b.data: [6 5]
however the augmented unmasked += masked applies the operation to all elements, regardless of any masked values:
a, b = ab()
a += b
print('a: {0}'.format(a))
# a: [6 6]
I would have expected a: [6 5]
, similar to b.data
shown above. Similar behavior is found with different augmented operators.
And as a side note, I get different behavior for unmasked + masked with different versions:
a, b = ab()
c = a + b
print('{0}: c: {1}; c.data: {2}'.format(np.__version__, c, c.data))
Testing a few versions that I have on-hand:
1.4.1: c: [6 --]; c.data: [6 5]
1.11.3: c: [6 --]; c.data: [6 1]
It’s a minor detail, but an odd one why these are different. The older NumPy behavior is similar to first augmented example which works as expected for both of these NumPy versions tested.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Data Augmentation with Masks - Apache MXNet
Segmentation tasks are structured in such a way that the data is the base image and the label is the mask, so we...
Read more >Can you assign only unmasked values using numpy.ma?
Is there a way to copy values from one numpy masked array to another where ONLY the unmasked values are copied and the...
Read more >A novel data augmentation approach for mask detection using ...
The proposed model is trained on a dataset of masked and unmasked people with the usage of a proper pre-processing technique [9]. This...
Read more >A novel data augmentation approach for mask ... - NCBI - NIH
The proposed model is trained on a dataset of masked and unmasked people with the usage of a proper pre-processing technique [9]. This...
Read more >Masked image modeling with Autoencoders - Keras
generate_masked_image -- Takes patches and unmask indices, results in a random masked image. This is an essential utility method for our ...
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 Free
Top 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
I would expect invalid values to be filled in by the
fill_value
@hmaarrfk: What else would you suggest could happen, other than perhaps a warning?