Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Inconsistent behaviour of masked arrays for equivalent operations #16359

Closed
@tirthasheshpatel

Description

@tirthasheshpatel

When a np.array (say a) is added with np.ma.masked_array (say ma) using a += ma operator, it gives a np.array output while a = a + ma gives a np.ma.maked_array output.

Reproducing code example:

>>> import numpy as np
>>> A = np.arange(10)
>>> ma = np.ma.masked_array(A, A>4)
>>> ma
masked_array(data=[0, 1, 2, 3, 4, --, --, --, --, --],
             mask=[False, False, False, False, False,  True,  True,  True,
                    True,  True],
       fill_value=999999)
>>> A += ma
>>> A
array([ 0,  2,  4,  6,  8, 10, 12, 14, 16, 18])
>>> A = A + ma
>>> A
masked_array(data=[0, 4, 8, 12, 16, --, --, --, --, --],
             mask=[False, False, False, False, False,  True,  True,  True,
                    True,  True],
       fill_value=999999)
>>>
import numpy as np
<< your code here >>

Error message:

Numpy/Python version information:

>>> np.__version__
'1.18.4'

Metadata

Metadata

Assignees

No one assigned

    Labels

    33 - QuestionQuestion about NumPy usage or development

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions