<commit_before>.. currentmodule:: numpy.ma

.. for doctests
   >>> from numpy import ma

.. _numpy.ma.constants:

Constants of the :mod:`numpy.ma` module
=======================================

In addition to the :class:`MaskedArray` class, the :mod:`numpy.ma` module
defines several constants.

.. data:: masked

   The :attr:`masked` constant is a special case of :class:`MaskedArray`,
   with a float datatype and a null shape. It is used to test whether a
   specific entry of a masked array is masked, or to mask one or several
   entries of a masked array::

      >>> x = ma.array([1, 2, 3], mask=[0, 1, 0])
      >>> x[1] is ma.masked
      True
      >>> x[-1] = ma.masked
      >>> x
      masked_array(data=[1, --, --],
                   mask=[False,  True,  True],
             fill_value=999999)


.. data:: nomask

   Value indicating that a masked array has no invalid entry.
   :attr:`nomask` is used internally to speed up computations when the mask
   is not needed. It is represented internally as ``np.False_``.


.. data:: masked_print_options

   String used in lieu of missing data when a masked array is printed.
   By default, this string is ``'--'``.




.. _maskedarray.baseclass:

The :class:`MaskedArray` class
==============================


.. class:: MaskedArray

A subclass of :class:`~numpy.ndarray` designed to manipulate numerical arrays with missing data.



An instance of :class:`MaskedArray` can be thought as the combination of several elements:

* The :attr:`~MaskedArray.data`, as a regular :class:`numpy.ndarray` of any shape or datatype (the data).
* A boolean :attr:`~numpy.ma.MaskedArray.mask` with the same shape as the data, where a ``True`` value indicates that the corresponding element of the data is invalid.
  The special value :const:`nomask` is also acceptable for arrays without named fields, and indicates that no data is invalid.
* A :attr:`~numpy.ma.MaskedArray.fill_value`, a value that may be used to replace the invalid entries in order to return a standard :class:`numpy.ndarray`.



.. _ma-attributes:

Attributes and properties of masked arrays
------------------------------------------

.. seealso:: :ref:`Array Attributes <arrays.ndarray.attributes>`<commit_msg>DOC: updated masked_print_option and added explanation (#22013)<commit_after>.. currentmodule:: numpy.ma

.. for doctests
   >>> from numpy import ma

.. _numpy.ma.constants:

Constants of the :mod:`numpy.ma` module
=======================================

In addition to the :class:`MaskedArray` class, the :mod:`numpy.ma` module
defines several constants.

.. data:: masked

   The :attr:`masked` constant is a special case of :class:`MaskedArray`,
   with a float datatype and a null shape. It is used to test whether a
   specific entry of a masked array is masked, or to mask one or several
   entries of a masked array::

      >>> x = ma.array([1, 2, 3], mask=[0, 1, 0])
      >>> x[1] is ma.masked
      True
      >>> x[-1] = ma.masked
      >>> x
      masked_array(data=[1, --, --],
                   mask=[False,  True,  True],
             fill_value=999999)


.. data:: nomask

   Value indicating that a masked array has no invalid entry.
   :attr:`nomask` is used internally to speed up computations when the mask
   is not needed. It is represented internally as ``np.False_``.


.. data:: masked_print_option

   String used in lieu of missing data when a masked array is printed.
   By default, this string is ``'--'``.

   Use ``set_display()`` to change the default string.
   Example usage: ``numpy.ma.masked_print_option.set_display('X')`` 
   replaces missing data with ``'X'``.

.. _maskedarray.baseclass:

The :class:`MaskedArray` class
==============================


.. class:: MaskedArray

A subclass of :class:`~numpy.ndarray` designed to manipulate numerical arrays with missing data.



An instance of :class:`MaskedArray` can be thought as the combination of several elements:

* The :attr:`~MaskedArray.data`, as a regular :class:`numpy.ndarray` of any shape or datatype (the data).
* A boolean :attr:`~numpy.ma.MaskedArray.mask` with the same shape as the data, where a ``True`` value indicates that the corresponding element of the data is invalid.
  The special value :const:`nomask` is also acceptable for arrays without named fields, and indicates that no data is invalid.
* A :attr:`~numpy.ma.MaskedArray.fill_value`, a value that may be used to replace the invalid entries in order to return a standard :class:`numpy.ndarray`.



.. _ma-attributes:

Attributes and properties of masked arrays
------------------------------------------

.. seealso:: :ref:`Array Attributes <arrays.ndarray.attributes>`
{'fraction_non_alphanumeric': 0.1513467293715263, 'fraction_numerical': 0.007481829841812741, 'mean_word_length': 3.3444753946146704, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5003508', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1298, 'n_words': 542}