{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "reference:maskedarray.generic",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "maskedarray.generic"
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "The "
        },
        {
          "__type": "InlineRole",
          "__tag": 4003,
          "value": "numpy.ma",
          "domain": null,
          "role": "mod",
          "inventory": null
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": " module"
        }
      ],
      "level": 0,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Masked arrays are arrays that may have missing or invalid entries. The "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.ma",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy.ma"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " module provides a nearly work-alike replacement for numpy that supports data arrays with masks."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Rationale"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data point, or recorded an invalid value. The "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.ma",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy.ma"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " module provides a convenient way to address this issue, by introducing masked arrays."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A masked array is the combination of a standard "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.ndarray",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:ndarray"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and a mask. A mask is either "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "nomask",
              "domain": null,
              "role": "attr",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", indicating that no value of the associated array is invalid, or an array of booleans that determines for each element of the associated array whether the value is valid or not. When an element of the mask is "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "False"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", the corresponding element of the associated array is valid and is said to be unmasked. When an element of the mask is "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", the corresponding element of the associated array is said to be masked (invalid)."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The package ensures that masked entries are not used in computations."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "What is a masked array?"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The main feature of the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.ma",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy.ma"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " module is the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "MaskedArray",
              "domain": null,
              "role": "class",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " class, which is a subclass of "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.ndarray",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:ndarray"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The class, its attributes and methods are described in more details in the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "MaskedArray class",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "reference:maskedarray.baseclass"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " section."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For a complete discussion of creation methods for masked arrays please see section "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "Constructing masked arrays",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "reference:maskedarray.generic"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "The "
        },
        {
          "__type": "InlineRole",
          "__tag": 4003,
          "value": "numpy.ma",
          "domain": null,
          "role": "mod",
          "inventory": null
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": " module"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Using numpy.ma"
        }
      ],
      "level": 0,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are several ways to construct a masked array."
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A first possibility is to directly invoke the "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "MaskedArray",
                      "domain": null,
                      "role": "class",
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " class."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A second possibility is to use the two masked array constructors,   "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "array",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "array",
                        "version": "*",
                        "kind": "api",
                        "path": "array"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "masked_array",
                      "domain": null,
                      "role": "func",
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": ".. autosummary:: \n    :toctree:generated/\n    array\n      masked_array",
                  "execution_status": null
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A third option is to take the view of an existing array. In that case, the   mask of the view is set to "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "nomask",
                      "domain": null,
                      "role": "attr",
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " if the array has no named fields,   or an array of boolean with the same structure as the array otherwise."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Yet another possibility is to use any of the following functions:"
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": ".. autosummary:: \n    :toctree:generated/\n    asarray\n      asanyarray\n      fix_invalid\n      masked_equal\n      masked_greater\n      masked_greater_equal\n      masked_inside\n      masked_invalid\n      masked_less\n      masked_less_equal\n      masked_not_equal\n      masked_object\n      masked_outside\n      masked_values\n      masked_where",
                  "execution_status": null
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Constructing masked arrays"
        }
      ],
      "level": 1,
      "target": "maskedarray.generic.constructing"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The underlying data of a masked array can be accessed in several ways:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "through the "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "~MaskedArray.data",
                      "domain": null,
                      "role": "attr",
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " attribute. The output is a view of the   array as a "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.ndarray",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy:ndarray"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or one of its subclasses, depending on the   type of the underlying data at the masked array creation."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "through the "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "~MaskedArray.__array__",
                      "domain": null,
                      "role": "meth",
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " method. The output is then a   "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.ndarray",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy:ndarray"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "by directly taking a view of the masked array as a "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.ndarray",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy:ndarray"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "   or one of its subclass (which is actually what using the   "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "~MaskedArray.data",
                      "domain": null,
                      "role": "attr",
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " attribute does)."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "by using the "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "getdata",
                      "domain": null,
                      "role": "func",
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " function."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "None of these methods is completely satisfactory if some entries have been marked as invalid. As a general rule, where a representation of the array is required without any masked entries, it is recommended to fill the array with the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "filled",
              "domain": null,
              "role": "meth",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " method."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Accessing the data"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The mask of a masked array is accessible through its "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "~MaskedArray.mask",
              "domain": null,
              "role": "attr",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " attribute. We must keep in mind that a "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " entry in the mask indicates an "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "invalid"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " data."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Another possibility is to use the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "getmask",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "getmaskarray",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " functions. "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "getmask(x)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " outputs the mask of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " if "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a masked array, and the special value "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "nomask",
              "domain": null,
              "role": "data",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " otherwise. "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "getmaskarray(x)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " outputs the mask of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " if "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a masked array. If "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " has no invalid entry or is not a masked array, the function outputs  a boolean array of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "False"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " with as many elements as "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Accessing the mask"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To retrieve only the valid entries, we can use the inverse of the mask as an index. The inverse of the mask can be calculated with the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.logical_not",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:logical_not"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " function or simply with the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "~"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " operator:"
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Accessing only the valid entries"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Modifying the mask"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The recommended way to mark one or several specific entries of a masked array as invalid is to assign the special value "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "masked",
              "domain": null,
              "role": "attr",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to them:"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A second possibility is to modify the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "~MaskedArray.mask",
              "domain": null,
              "role": "attr",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " directly, but this usage is discouraged."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "When creating a new masked array with a simple, non-structured datatype, the mask is initially set to the special value "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "nomask",
                  "domain": null,
                  "role": "attr",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", that corresponds roughly to the boolean "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "False"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ". Trying to set an element of "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "nomask",
                  "domain": null,
                  "role": "attr",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " will fail with a "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "TypeError",
                  "domain": null,
                  "role": "exc",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " exception, as a boolean does not support item assignment."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "All the entries of an array can be masked at once by assigning "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to the mask:"
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Masking an entry"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To unmask one or several specific entries, we can just assign one or several new valid values to them:"
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Unmasking an entry by direct assignment will silently fail if the masked array has a "
                },
                {
                  "__type": "Emphasis",
                  "__tag": 4047,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "hard"
                    }
                  ]
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " mask, as shown by the "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "~MaskedArray.hardmask",
                  "domain": null,
                  "role": "attr",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " attribute. This feature was introduced to prevent overwriting the mask. To force the unmasking of an entry where the array has a hard mask, the mask must first to be softened using the "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "soften_mask",
                  "domain": null,
                  "role": "meth",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " method before the allocation. It can be re-hardened with "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "harden_mask",
                  "domain": null,
                  "role": "meth",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " as follows:"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To unmask all masked entries of a masked array (provided the mask isn't a hard mask), the simplest solution is to assign the constant "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "nomask",
              "domain": null,
              "role": "attr",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to the mask:"
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Unmasking an entry"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "As a "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "MaskedArray",
              "domain": null,
              "role": "class",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a subclass of "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.ndarray",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:ndarray"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", it inherits its mechanisms for indexing and slicing."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When accessing a single entry of a masked array with no named fields, the output is either a scalar (if the corresponding entry of the mask is "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "False"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") or the special value "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "masked",
              "domain": null,
              "role": "attr",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (if the corresponding entry of the mask is "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "True"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "):"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If the masked array has named fields, accessing a single entry returns a "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.void",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:void"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " object if none of the fields are masked, or a 0d masked array with the same dtype as the initial array if at least one of the fields is masked."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When accessing a slice, the output is a masked array whose "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "~MaskedArray.data",
              "domain": null,
              "role": "attr",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " attribute is a view of the original data, and whose mask is either "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "nomask",
              "domain": null,
              "role": "attr",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (if there was no invalid entries in the original array) or a view of the corresponding slice of the original mask. The view is required to ensure propagation of any modification of the mask to the original."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Accessing a field of a masked array with structured datatype returns a "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "MaskedArray",
              "domain": null,
              "role": "class",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Indexing and slicing"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Arithmetic and comparison operations are supported by masked arrays. As much as possible, invalid entries of a masked array are not processed, meaning that the corresponding "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "~MaskedArray.data",
              "domain": null,
              "role": "attr",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " entries "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "should"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " be the same before and after the operation."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "warning",
          "base_type": "warning",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "warning "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "We need to stress that this behavior may not be systematic, that masked data may be affected by the operation in some cases and therefore users should not rely on this data remaining unchanged."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.ma",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy.ma"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " module comes with a specific implementation of most ufuncs. Unary and binary functions that have a validity domain (such as "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "log",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:log"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "divide",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy:divide"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") return the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "masked",
              "domain": null,
              "role": "data",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " constant whenever the input is masked or falls outside the validity domain:"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Masked arrays also support standard numpy ufuncs. The output is then a masked array. The result of a unary ufunc is masked wherever the input is masked. The result of a binary ufunc is masked wherever any of the input is masked. If the ufunc also returns the optional context output (a 3-element tuple containing the name of the ufunc, its arguments and its domain), the context is processed and entries of the output masked array are masked wherever the corresponding input fall outside the validity domain:"
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Operations on masked arrays"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Examples"
        }
      ],
      "level": 0,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Let's consider a list of elements, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", where values of -9999. represent missing data. We wish to compute the average value of the data and the vector of anomalies (deviations from the average):"
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Data with a given value representing missing data"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Suppose now that we wish to print that same data, but with the missing values replaced by the average value."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Filling in the missing data"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Numerical operations can be easily performed without worrying about missing values, dividing by zero, square roots of negative numbers, etc.:"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Four values of the output are invalid: the first one comes from taking the square root of a negative number, the second from the division by zero, and the last two where the inputs were masked."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Numerical operations"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Let's consider an array "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "d"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " of floats between 0 and 1. We wish to compute the average of the values of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "d"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " while ignoring any data outside the range "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "[0.2, 0.9]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Ignoring extreme values"
        }
      ],
      "level": 1,
      "target": null
    }
  ],
  "local_refs": []
}