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.

Augmented assignments between unmasked and masked arrays

See original GitHub issue

I’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:open
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
hmaarrfkcommented, Oct 17, 2018

I would expect invalid values to be filled in by the fill_value

0reactions
eric-wiesercommented, Oct 17, 2018

@hmaarrfk: What else would you suggest could happen, other than perhaps a warning?

Read more comments on GitHub >

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

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