????

Your IP : 13.59.219.20


Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/ma/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/ma/__pycache__/core.cpython-311.pyc

�

�܋f>�
���dZddlZddlZddlZddlZddlZddlZddlmZddl	Z
ddlmcm
Z
ddlmcmZddlmZddl	mZmZmZmZmZmZddl	mZddlmZddlmZm Z m!Z!m"Z"m#Z#dd	l	m$Z$dd
l%m&Z&gd�Z'e
jZ(e(d��Z)Gd�d
e*��Z+d�Z,d�Z-d�Z.Gd�de/��Z0Gd�de0��Z1dddddddddd�	Z2dD]6Z3e
j4de3��e2d e3zd!z<e
j5de3��e2d"e3zd!z<�7e
j6e
j7e
j8e
j9e
j:e
j;e
j<gZ=ej>Z?e?�@d#�e=dd$�D����e?�@d%�e=d&d�D����ejAZBeB�@d'�e=dd$�D����eB�@d(�e=d&d�D����[=d)�ZCd*�ZDd+�ZEd,�ZFd-�ZGd.�ZHd/�ZId0�ZJd1�ZKd2�ZLd3�ZMd�d4�ZNd5�ZOd�d6�ZPePZQe)ddfd7�ZRd8�ZSiZTiZUGd9�d:��ZVGd;�d<��ZWGd=�d>��ZXGd?�d@��ZYGdA�dB��ZZGdC�dD��Z[GdE�dFe[��Z\GdG�dHe[��Z]GdI�dJe[��Z^e\e
j_��Z_e\e
j`��Z`e\e
ja��Zae\e
jb��Zbe\e
jc��Zce\e
jd��Zde\e
je��Zee\e
jf��Zfe\e
jg��Zge\e
jh��xZiZhe\e��Ze\e
jj��Zje\e
jk��Zke\e
jl��Zle\e
jm��Zme\e
jn��Zoe\e
jp��Zpe\e
jqdKeZdK����Zqe\e
jrdLeYdK����Zre\e
jsdLeYdK����Zse\e
jtdLeYdK����Zte\e
judKeWdM����Zue\e
jvdKeVdNdL����Zve\e
jwdKeVdNdL����Zwe\e
jxdLeZdL����Zxe\e
jydKeVdOdP����Zye]e
jz��Zze]e
j{��Z{e]e
j|dQdQ��Z|e]e
j}dKdL��Z}e]e
j~��Z~de~_e]e
j��Zde_e]e
j���Z�de�_e]e
j���Z�de�_e]e
j���Z�de�_e]e
j���Z�de�_e]e
j���Z�e]e
j�dQdQ��jZ�e]e
j���Z�e�jZ�e]e
j���Z�e]e
j���Z�e]e
j���Z�e]e
j���Z�e]e
j���Z�e^e
j�eX��ddQ��Z�e^e
j�eX��ddQ��Z�e^e
j�eX��ddQ��Z�e^e
j�eX��ddQ��Z�e^e
j�eX��ddQ��Z�e^e
j�eX��ddQ��Z�dR�Z�dS�Z�dT�Z�dU�Z�e�Z�dV�Z�dW�Z�dX�Z�dYde(fdZ�Z�d�d[�Z�d\�Z�d�d]�Z�d^�Z�e
jfd_�Z�d�d`�Z�d�da�Z�d�db�Z�d�dc�Z�d�dd�Z�d�de�Z�d�df�Z�d�dg�Z�d�dh�Z�d�di�Z�d�dl�Z�d�dm�Z�Gdn�do��Z�e�dp��Z�dq�Z�e�ej�dr��ej�ds��ej�dt��ej�du���v��Z�dw�Z�dx�Z�d�dy�Z�Gdz�d{��Z�Gd|�d}e��Z�d~�Z�Gd�d�e���Z�d��Z�e�Z�e�Z�Gd��d�e���Z�e���xZ�Z�e�Z�ddYde)dddYdddf
d��Ze�je_d��Z�Gd��d�e[��Z�ddde
jfd��Z�e�j�je�_ddde
jfd��Z�e�j�je�_ddde
jfd��Z�e�j�je�_Gd��d���Z�e�d���Z�e�d���xZ�Z�e�d���Z�e�d�d����Z�e�d���Z�e�d���Z�e�d���Z�e�d���Z�e�d���Z�e�d���Z�e�e
j�e�eH��Z�e�d���Z�e�e
j�e�eG��Z�e�d���Z�e�d���Z�e�d���Z�e�d���Z�e�d���Z�e�d���Z�e�d���Z�e�d���Z�e�d���Z�e�d���Z�e�d���Z�e�d���Z�e�d���Z�d�d��Z�d�d��Z�e�d���Z�e�d���Z�e
jddddfd��Z�e�j�je�_d�d��Z�d��Z�d�d��Z�d�d��Z�d��Z�d��Z�d�d��Z�d��Z�d�d��Z�d�d��Z�d��Z�d��Z�e
j�je�_d��Z�e
j�je�_d�d��Z�e
j�je�_dQd�e
je
jfd��Z�eefd��Z�d�d��Z�d�d��ZnenZ�d��Z�d�d��Z�d��Z�e-e
j�jd¦�e�_e�Z�dÄZ�e-e
j�jd¦�e�_e�Z�dĄZ�d�dƄ�Zd�dȄ�Zd�dɄ�Zd�dʄ�Z�dd˄�Zd�d̄�Z�ed�d�fd΄�Zdτ�ZGdЄdѦ��Z	�e	d�e�ddY�Ӧ�d�dլ֦��Z
�e	d�e�ddY�Ӧ�d�d٬֦��Z�e	d�e�ddY�Ӧ�d�dܬ֦��Z�e	d�d�dܬަ��Z
�e	d�d�d�ަ��Z�e	d�d�d�ަ��Z�e	d�e�ddY�Ӧ�d�dܬ֦��Z�e	d�e�ddY�Ӧ�d�d�֦��Z�e	d�e�ddY�Ӧ�d�dܬ֦��Z�e	d�d�dܬަ��Z�e	d�e�ddY�Ӧ�d�d�֦��Z�e	d�e�ddY�Ӧ�d�dܬ֦��Z�e	d�d�dܬަ��Zd�d��ZdS(a�
numpy.ma : a package to handle missing or invalid values.

This package was initially written for numarray by Paul F. Dubois
at Lawrence Livermore National Laboratory.
In 2006, the package was completely rewritten by Pierre Gerard-Marchant
(University of Georgia) to make the MaskedArray class a subclass of ndarray,
and to improve support of structured arrays.


Copyright 1999, 2000, 2001 Regents of the University of California.
Released for unlimited redistribution.

* Adapted for numpy_core 2005 by Travis Oliphant and (mainly) Paul Dubois.
* Subclassing of the base `ndarray` 2006 by Pierre Gerard-Marchant
  (pgmdevlist_AT_gmail_DOT_com)
* Improvements suggested by Reggie Dugard (reggie_AT_merfinllc_DOT_com)

.. moduleauthor:: Pierre Gerard-Marchant

�N)�reduce)�
multiarray)�ndarray�amax�amin�iscomplexobj�bool_�_NoValue)�array)�angle)�
getargspec�
formatargspec�long�unicode�bytes)�expand_dims)�normalize_axis_tuple)��MAError�	MaskError�MaskType�MaskedArray�abs�absolute�add�all�allclose�allequal�alltruerrr�anom�	anomalies�any�append�arange�arccos�arccosh�arcsin�arcsinh�arctan�arctan2�arctanh�argmax�argmin�argsort�aroundr�
asanyarray�asarray�bitwise_and�
bitwise_or�bitwise_xorr	�ceil�choose�clip�common_fill_value�compress�
compressed�concatenate�	conjugate�convolve�copy�	correlate�cos�cosh�count�cumprod�cumsum�default_fill_value�diag�diagonal�diff�divide�empty�
empty_like�equal�expr�fabs�filled�fix_invalid�flatten_mask�flatten_structured_array�floor�floor_divide�fmod�
frombuffer�fromflex�fromfunction�getdata�getmask�getmaskarray�greater�
greater_equal�harden_mask�hypot�identity�ids�indices�inner�innerproduct�isMA�
isMaskedArray�is_mask�	is_masked�isarray�
left_shift�less�
less_equal�log�log10�log2�logical_and�logical_not�
logical_or�logical_xor�	make_mask�make_mask_descr�make_mask_none�mask_or�masked�masked_array�masked_equal�masked_greater�masked_greater_equal�
masked_inside�masked_invalid�masked_less�masked_less_equal�masked_not_equal�
masked_object�masked_outside�masked_print_option�masked_singleton�
masked_values�masked_where�max�maximum�maximum_fill_value�mean�min�minimum�minimum_fill_value�mod�multiply�mvoid�ndim�negative�nomask�nonzero�	not_equal�ones�	ones_like�outer�outerproduct�power�prod�product�ptp�put�putmask�ravel�	remainder�repeat�reshape�resize�right_shift�round�round_�set_fill_value�shape�sin�sinh�size�soften_mask�sometrue�sort�sqrt�squeeze�std�subtract�sum�swapaxes�take�tan�tanh�trace�	transpose�true_divide�var�where�zeros�
zeros_likec��eZdZdS)�MaskedArrayFutureWarningN)�__name__�
__module__�__qualname__���D/opt/cloudlinux/venv/lib64/python3.11/site-packages/numpy/ma/core.pyr�r�Ts�������Dr�r�c�X�|jdkrdStjdtd���dS)a�
    Adjust the axis passed to argsort, warning if necessary

    Parameters
    ----------
    arr
        The array which argsort was called on

    np.ma.argsort has a long-term bug where the default of the axis argument
    is wrong (gh-8701), which now must be kept for backwards compatibility.
    Thankfully, this only makes a difference when arrays are 2- or more-
    dimensional, so we only need a warning then.
    ����z�In the future the default for argsort will be axis=-1, not the current None, to match its documentation and np.argsort. Explicitly pass -1 or None to silence this warning.���
stacklevelN)r��warnings�warnr�)�arrs r��_deprecate_argsort_axisr�WsE���x�1�}�}��r�	�
�
B�
%��		4�	4�	4�	4�
�tr�c���|�dS|�|Stjdtj|����}dtj|��z}d�|dd�|gz|dd�z��S)z9
    Adds a Notes section to an existing docstring.

    Nz\n\s*?Notes\n\s*?-----z

Notes
-----
%s
�r�)�re�split�inspect�cleandoc�join)�
initialdoc�note�	notesplit�notedocs    r��doc_noter�ssz��
�����|�����2�G�4D�Z�4P�4P�Q�Q�I�&��)9�$�)?�)?�?�G�
�7�7�9�R�a�R�=�G�9�,�y����}�<�=�=�=r�c�Z�	tt|���}n#t$rd}YnwxYw|S)z%
    Get the signature from obj

    r�)rr
�	TypeError)�obj�sigs  r��get_object_signaturer��sB��
��Z��_�_�-�����������������Js��(�(c��eZdZdZdS)rz1
    Class for masked array related errors.

    N�r�r�r��__doc__r�r�r�rr����������	�Dr�rc��eZdZdZdS)rz)
    Class for mask related errors.

    Nr�r�r�r�rr�r�r�rTy@��x�Dg@��x�Di?B�?sN/As???zN/A)	�b�c�f�i�O�S�u�V�U)
�Y�M�W�D�h�m�s�ms�us�ns�ps�fs�as�NaTzM8[�]zm8[c�,�g|]}|tjf��Sr���np�inf��.0�ks  r��
<listcomp>r�s ��>�>�>�A�A���w�<�>�>�>r��c�^�g|]*}|ttjtj��f��+Sr���complexrrrs  r�rr��/��Q�Q�Q�a�A�w���w����0�0�1�Q�Q�Qr����c�,�g|]}|tj
f��Sr�rrs  r�rr�s ��?�?�?�Q�A����=�?�?�?r�c�^�g|]*}|ttj
tj
��f��+Sr�rrs  r�rr�r
r�c�����j�=t��fd��jD����}tj|����dS�jr/�j\}}t|���}tj||��S����S)zR
    Recursively produce a fill value for `dtype`, calling f on scalar dtypes
    Nc3�h�K�|],}tjt�|�����V��-dS�N)rr�_recursive_fill_value)r�name�dtyper�s  ��r��	<genexpr>z(_recursive_fill_value.<locals>.<genexpr>�sP�����)�)����.�u�T�{�A�>�>�?�?�)�)�)�)�)�)r��rr�)�names�tuplerr�subdtyper�full)rr��vals�subtyper��subvals``    r�rr�s�����
�{��
�)�)�)�)�)�!�K�)�)�)�)�)���x��E�*�*�*�2�.�.�	��������&�w��2�2���w�u�f�%�%�%��q��x�x�r�c��t|tj��r|St|d��r|jStj|��jS)z4 Convert the argument for *_fill_value into a dtype r)�
isinstancerr�hasattrr/�r�s r��
_get_dtype_ofr$�sH���#�r�x� � �(��
�	��g�	�	�(��y���}�S�!�!�'�'r�c�F�d�}t|��}t||��S)aN
    Return the default fill value for the argument object.

    The default filling value depends on the datatype of the input
    array or the type of the input scalar:

       ========  ========
       datatype  default
       ========  ========
       bool      True
       int       999999
       float     1.e20
       complex   1.e20+0j
       object    '?'
       string    'N/A'
       ========  ========

    For structured types, a structured scalar is returned, with each field the
    default fill value for its type.

    For subarray types, the fill value is an array of the same size containing
    the default scalar fill value.

    Parameters
    ----------
    obj : ndarray, dtype or scalar
        The array data-type or scalar for which the default fill value
        is returned.

    Returns
    -------
    fill_value : scalar
        The default fill value.

    Examples
    --------
    >>> np.ma.default_fill_value(1)
    999999
    >>> np.ma.default_fill_value(np.array([1.1, 2., np.pi]))
    1e+20
    >>> np.ma.default_fill_value(np.dtype(complex))
    (1e+20+0j)

    c��|jdvr(t�|jdd�d��St�|jd��S)N�Mmr�r�)�kind�default_filler�get�strrs r��_scalar_fill_valuez.default_fill_value.<locals>._scalar_fill_valuesG���:����!�%�%�e�i����m�S�9�9�9�!�%�%�e�j�#�6�6�6r��r$r)r�r,rs   r�rDrD�s2��Z7�7�7�
�#���E� ��(:�;�;�;r�c�P�����fd�}t|��}t||��S)Nc�h��	�|S#t$r}td|�d��d���d�d}~wwxYw)NzUnsuitable type z for calculating �.)�KeyErrorr�)r�e�extremum�
extremum_names  ��r�r,z0_extremum_fill_value.<locals>._scalar_fill_values\���	��E�?�"���	�	�	��K�5�K�K�=�K�K�K����
�����	���s��
1�,�1r-)r�r3r4r,rs ``  r��_extremum_fill_valuer5sB����������
�#���E� ��(:�;�;�;r�c�.�t|td��S)a`
    Return the maximum value that can be represented by the dtype of an object.

    This function is useful for calculating a fill value suitable for
    taking the minimum of an array with a given dtype.

    Parameters
    ----------
    obj : ndarray, dtype or scalar
        An object that can be queried for it's numeric type.

    Returns
    -------
    val : scalar
        The maximum representable value.

    Raises
    ------
    TypeError
        If `obj` isn't a suitable numeric type.

    See Also
    --------
    maximum_fill_value : The inverse function.
    set_fill_value : Set the filling value of a masked array.
    MaskedArray.fill_value : Return current fill value.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.int8()
    >>> ma.minimum_fill_value(a)
    127
    >>> a = np.int32()
    >>> ma.minimum_fill_value(a)
    2147483647

    An array of numeric data can also be passed.

    >>> a = np.array([1, 2, 3], dtype=np.int8)
    >>> ma.minimum_fill_value(a)
    127
    >>> a = np.array([1, 2, 3], dtype=np.float32)
    >>> ma.minimum_fill_value(a)
    inf

    r�)r5�
min_fillerr#s r�r�r�+���` ��Z��;�;�;r�c�.�t|td��S)ad
    Return the minimum value that can be represented by the dtype of an object.

    This function is useful for calculating a fill value suitable for
    taking the maximum of an array with a given dtype.

    Parameters
    ----------
    obj : ndarray, dtype or scalar
        An object that can be queried for it's numeric type.

    Returns
    -------
    val : scalar
        The minimum representable value.

    Raises
    ------
    TypeError
        If `obj` isn't a suitable numeric type.

    See Also
    --------
    minimum_fill_value : The inverse function.
    set_fill_value : Set the filling value of a masked array.
    MaskedArray.fill_value : Return current fill value.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.int8()
    >>> ma.maximum_fill_value(a)
    -128
    >>> a = np.int32()
    >>> ma.maximum_fill_value(a)
    -2147483648

    An array of numeric data can also be passed.

    >>> a = np.array([1, 2, 3], dtype=np.int8)
    >>> ma.maximum_fill_value(a)
    -128
    >>> a = np.array([1, 2, 3], dtype=np.float32)
    >>> ma.maximum_fill_value(a)
    -inf

    r�)r5�
max_fillerr#s r�r�r�^r8r�c	���tj|t|j����}g}t	||j��D]�\}}||}|jr
|jd}|j�1|�tt||�������Y|�tj	||����
������t|��S)a�
    Create a fill value for a structured dtype.

    Parameters
    ----------
    fillvalue : scalar or array_like
        Scalar or array representing the fill value. If it is of shorter
        length than the number of fields in dt, it will be resized.
    dt : dtype
        The structured dtype for which to create the fill value.

    Returns
    -------
    val : tuple
        A tuple of values corresponding to the structured fill value.

    rNr)rr��lenr�ziprr"r�_recursive_set_fill_valuer�item)�	fillvalue�dt�output_value�fvalr�cdtypes      r�r>r>�s���$�	�)�S���]�]�3�3�I��L��I�r�x�0�0�E�E���t��D����?�	(��_�Q�'�F��<�#�����&?��f�&M�&M� N� N�O�O�O�O�������V� <� <� <� A� A� C� C�D�D�D�D�����r�c���tj|��}|�t|��}�n%|j��t	|t
tjf��rB	tj|d|���}n�#t$r}d}t|||fz��|�d}~wwxYwtj	|t���}tjt||��|���}n{t	|t��r|j
dvrd}t||z���	tj|d|���}n0#ttf$r}d}t|||fz��|�d}~wwxYwtj|��S)	a
    Private function validating the given `fill_value` for the given dtype.

    If fill_value is None, it is set to the default corresponding to the dtype.

    If fill_value is not None, its value is forced to the given dtype.

    The result is always a 0d array.

    NF�r=rz"Unable to transform %s to dtype %sr�OSVUz6Cannot set fill value of string with array of dtype %sz(Cannot convert fill_value %s to dtype %s)rrrDrr!r�voidr�
ValueErrorr0�objectr>r+�charr��
OverflowError)�
fill_value�ndtyper2�err_msgs    r��_check_fill_valuerP�s����X�f�
�
�F���'��/�/�
�
�	��	!��j�7�B�G�"4�5�5�		0�
H��X�j�u�F�K�K�K�
�
���
H�
H�
H�>�� ��J��+?�!?�@�@�a�G�����
H������J�f�=�=�=�J���";�J��"O�"O�(.�0�0�0�J�J��j�#�&�&�	G�F�K�v�,E�,E�N�G��G�f�,�-�-�-�
G��X�j�u�F�K�K�K�
�
��!�:�.�
G�
G�
G�E����:�v�*>� >�?�?�Q�F�����
G�����8�J���s0�A)�)
B�3B
�
B�D�E
�.E�E
c�Z�t|t��r|�|��dS)a�
    Set the filling value of a, if a is a masked array.

    This function changes the fill value of the masked array `a` in place.
    If `a` is not a masked array, the function returns silently, without
    doing anything.

    Parameters
    ----------
    a : array_like
        Input array.
    fill_value : dtype
        Filling value. A consistency test is performed to make sure
        the value is compatible with the dtype of `a`.

    Returns
    -------
    None
        Nothing returned by this function.

    See Also
    --------
    maximum_fill_value : Return the default fill value for a dtype.
    MaskedArray.fill_value : Return current fill value.
    MaskedArray.set_fill_value : Equivalent method.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.arange(5)
    >>> a
    array([0, 1, 2, 3, 4])
    >>> a = ma.masked_where(a < 3, a)
    >>> a
    masked_array(data=[--, --, --, 3, 4],
                 mask=[ True,  True,  True, False, False],
           fill_value=999999)
    >>> ma.set_fill_value(a, -999)
    >>> a
    masked_array(data=[--, --, --, 3, 4],
                 mask=[ True,  True,  True, False, False],
           fill_value=-999)

    Nothing happens if `a` is not a masked array.

    >>> a = list(range(5))
    >>> a
    [0, 1, 2, 3, 4]
    >>> ma.set_fill_value(a, 100)
    >>> a
    [0, 1, 2, 3, 4]
    >>> a = np.arange(5)
    >>> a
    array([0, 1, 2, 3, 4])
    >>> ma.set_fill_value(a, 100)
    >>> a
    array([0, 1, 2, 3, 4])

    N)r!rr���arMs  r�r�r��s0��x�!�[�!�!�%�	����$�$�$�
�Fr�c�^�t|t��r|j}nt|��}|S)zr
    Return the filling value of a, if any.  Otherwise, returns the
    default filling value for that type.

    )r!rrMrD)rS�results  r��get_fill_valuerVs1���!�[�!�!�'�����#�A�&�&���Mr�c�R�t|��}t|��}||kr|SdS)a
    Return the common filling value of two masked arrays, if any.

    If ``a.fill_value == b.fill_value``, return the fill value,
    otherwise return None.

    Parameters
    ----------
    a, b : MaskedArray
        The masked arrays for which to compare fill values.

    Returns
    -------
    fill_value : scalar or None
        The common fill value, or None.

    Examples
    --------
    >>> x = np.ma.array([0, 1.], fill_value=3)
    >>> y = np.ma.array([0, 1.], fill_value=3)
    >>> np.ma.common_fill_value(x, y)
    3.0

    N)rV)rSr��t1�t2s    r�r7r7+s1��2
��	�	�B�	��	�	�B�	�R�x�x��	��4r�c��t|d��r|�|��St|t��r|St|t��rtj|d��Stj|��S)a�
    Return input as an array with masked data replaced by a fill value.

    If `a` is not a `MaskedArray`, `a` itself is returned.
    If `a` is a `MaskedArray` and `fill_value` is None, `fill_value` is set to
    ``a.fill_value``.

    Parameters
    ----------
    a : MaskedArray or array_like
        An input object.
    fill_value : array_like, optional.
        Can be scalar or non-scalar. If non-scalar, the
        resulting filled array should be broadcastable
        over input array. Default is None.

    Returns
    -------
    a : ndarray
        The filled array.

    See Also
    --------
    compressed

    Examples
    --------
    >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
    ...                                                   [1, 0, 0],
    ...                                                   [0, 0, 0]])
    >>> x.filled()
    array([[999999,      1,      2],
           [999999,      4,      5],
           [     6,      7,      8]])
    >>> x.filled(fill_value=333)
    array([[333,   1,   2],
           [333,   4,   5],
           [  6,   7,   8]])
    >>> x.filled(fill_value=np.arange(3))
    array([[0, 1, 2],
           [0, 4, 5],
           [6, 7, 8]])

    rNr�)r"rNr!r�dictrrrRs  r�rNrNKsr��Z�q�(���	��x�x�
�#�#�#�	�A�w�	�	����	�A�t�	�	���x��3�����x��{�{�r�c�X�t|��dkr5|d}t|t��rt|��}nWt}nOd�|D��}|d}t	|t��st}|dd�D]}t	||��r|}�|jdkrtS|S)z�
    Return the youngest subclass of MaskedArray from a list of (masked) arrays.

    In case of siblings, the first listed takes over.

    r�rc�,�g|]}t|����Sr�)�type�rrSs  r�rz'get_masked_subclass.<locals>.<listcomp>�s��*�*�*�a�$�q�'�'�*�*�*r�N�MaskedConstant)r<r!rr^�
issubclassr�)�arraysr��rcls�arrcls�clss     r��get_masked_subclassrf�s����6�{�{�a����Q�i���c�;�'�'�	���9�9�D�D��D�D�*�*�6�*�*�*���a�y���$��,�,�	��D��!�"�"�:�	�	�C��#�t�$�$�
�����}�(�(�(����Kr�c��	|j}n'#t$rtj|d|���}YnwxYw|s|�t
��S|S)aE
    Return the data of a masked array as an ndarray.

    Return the data of `a` (if any) as an ndarray if `a` is a ``MaskedArray``,
    else return `a` as a ndarray or subclass (depending on `subok`) if not.

    Parameters
    ----------
    a : array_like
        Input ``MaskedArray``, alternatively a ndarray or a subclass thereof.
    subok : bool
        Whether to force the output to be a `pure` ndarray (False) or to
        return a subclass of ndarray if appropriate (True, default).

    See Also
    --------
    getmask : Return the mask of a masked array, or nomask.
    getmaskarray : Return the mask of a masked array, or full array of False.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = ma.masked_equal([[1,2],[3,4]], 2)
    >>> a
    masked_array(
      data=[[1, --],
            [3, 4]],
      mask=[[False,  True],
            [False, False]],
      fill_value=2)
    >>> ma.getdata(a)
    array([[1, 2],
           [3, 4]])

    Equivalently use the ``MaskedArray`` `data` attribute.

    >>> a.data
    array([[1, 2],
           [3, 4]])

    F�r=�subok)�_data�AttributeErrorrr�viewr)rSri�datas   r�rXrX�se��T4��w�����4�4�4��x���U�3�3�3����4�����"��y�y��!�!�!��Ks�
�!.�.c���t|||d���}tjtj|j����}|���s|S|xj|zc_|�|j}||j|<|S)aQ
    Return input with invalid data masked and replaced by a fill value.

    Invalid data means values of `nan`, `inf`, etc.

    Parameters
    ----------
    a : array_like
        Input array, a (subclass of) ndarray.
    mask : sequence, optional
        Mask. Must be convertible to an array of booleans with the same
        shape as `data`. True indicates a masked (i.e. invalid) data.
    copy : bool, optional
        Whether to use a copy of `a` (True) or to fix `a` in place (False).
        Default is True.
    fill_value : scalar, optional
        Value used for fixing invalid data. Default is None, in which case
        the ``a.fill_value`` is used.

    Returns
    -------
    b : MaskedArray
        The input array with invalid entries fixed.

    Notes
    -----
    A copy is performed by default.

    Examples
    --------
    >>> x = np.ma.array([1., -1, np.nan, np.inf], mask=[1] + [0]*3)
    >>> x
    masked_array(data=[--, -1.0, nan, inf],
                 mask=[ True, False, False, False],
           fill_value=1e+20)
    >>> np.ma.fix_invalid(x)
    masked_array(data=[--, -1.0, --, --],
                 mask=[ True, False,  True,  True],
           fill_value=1e+20)

    >>> fixed = np.ma.fix_invalid(x)
    >>> fixed.data
    array([ 1.e+00, -1.e+00,  1.e+20,  1.e+20])
    >>> x.data
    array([ 1., -1., nan, inf])

    T)r=�maskri)rxrrp�isfiniterjr!�_maskrM)rSror=rM�invalids     r�rOrO�sy��`	�Q�T��D�9�9�9�A��n�R�[���1�1�2�2�G��;�;�=�=�����G�G�w��G�G����\�
�!�A�G�G���Hr�c��t|t��p4t|t��o|otjd�|D����S)Nc3�@K�|]}t|t��V��dSr)r!r+)rr�s  r�rz/is_string_or_list_of_strings.<locals>.<genexpr>s,����:�:��*�Q��,�,�:�:�:�:�:�:r�)r!r+�list�builtinsr)�vals r��is_string_or_list_of_stringsrxsN���s�C� � �
<�
��T�
"�
"�;�s�;�
�\�:�:�c�:�:�:�
:�
:�=r�c��eZdZdZd�Zd�ZdS)�_DomainCheckIntervalz~
    Define a valid interval, so that :

    ``domain_check_interval(a,b)(x) == True`` where
    ``x < a`` or ``x > b``.

    c�6�||kr||}}||_||_dS)z9domain_check_interval(a,b)(x) = true where x < a or y > bN)rSr���selfrSr�s   r��__init__z_DomainCheckInterval.__init__&s&���q�5�5����Q��������r�c���tjd���5tjtj||j��tj||j����cddd��S#1swxYwYdS)�Execute the call behavior.�ignore�rrN)r�errstate�umathrqr[r�rjrS�r}�xs  r��__call__z_DomainCheckInterval.__call__-s����[��
*�
*�
*�	;�	;��#�E�M�!�T�V�$<�$<�$)�J�q�$�&�$9�$9�;�;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;����	;�	;�	;�	;�	;�	;s�AA(�(A,�/A,N�r�r�r�r�r~r�r�r�r�rzrzs<�����������;�;�;�;�;r�rzc��eZdZdZd�Zd�ZdS)�
_DomainTanz
    Define a valid interval for the `tan` function, so that:

    ``domain_tan(eps) = True`` where ``abs(cos(x)) < eps``

    c��||_dS)z/domain_tan(eps) = true where abs(cos(x)) < eps)N)�eps)r}r�s  r�r~z_DomainTan.__init__>s
������r�c���tjd���5tjtjtj|����|j��cddd��S#1swxYwYdS��Executes the call behavior.r�r�N)rr�r�rjrr?r�r�s  r�r�z_DomainTan.__call__Bs���
�[��
*�
*�
*�	F�	F��:�e�n�U�Y�q�\�\�:�:�D�H�E�E�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F����	F�	F�	F�	F�	F�	Fs�>A!�!A%�(A%Nr�r�r�r�r�r�6sA�����������F�F�F�F�Fr�r�c� �eZdZdZdd�Zd�ZdS)�_DomainSafeDividez-
    Define a domain for safe division.

    Nc��||_dSr)�	tolerance)r}r�s  r�r~z_DomainSafeDivide.__init__Ns
��"����r�c�h�|j�#tjt��j|_tj|��tj|��}}tjd���5tj|��|jztj|��kcddd��S#1swxYwYdS)Nr�r�)	r�r�finfo�float�tinyr0r�r�rr|s   r�r�z_DomainSafeDivide.__call__Qs����>�!��X�e�_�_�1�D�N��z�!�}�}�b�j��m�m�1��
�[��
*�
*�
*�	K�	K��>�!�$�$�t�~�5����9J�9J�J�	K�	K�	K�	K�	K�	K�	K�	K�	K�	K�	K�	K����	K�	K�	K�	K�	K�	Ks�(2B'�'B+�.B+rr�r�r�r�r�r�HsF��������
#�#�#�#�	K�	K�	K�	K�	Kr�r�c��eZdZdZd�Zd�ZdS)�_DomainGreaterz4
    DomainGreater(v)(x) is True where x <= v.

    c��||_dS)z'DomainGreater(v)(x) = true where x <= vN��critical_value�r}r�s  r�r~z_DomainGreater.__init__c���,����r�c��tjd���5tj||j��cddd��S#1swxYwYdSr�)rr�r�rkr�r�s  r�r�z_DomainGreater.__call__gs���
�[��
*�
*�
*�	<�	<��#�A�t�':�;�;�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<����	<�	<�	<�	<�	<�	<��=�A�ANr�r�r�r�r�r�]s<��������
-�-�-�<�<�<�<�<r�r�c��eZdZdZd�Zd�ZdS)�_DomainGreaterEqualz8
    DomainGreaterEqual(v)(x) is True where x < v.

    c��||_dS)z+DomainGreaterEqual(v)(x) = true where x < vNr�r�s  r�r~z_DomainGreaterEqual.__init__sr�r�c��tjd���5tj||j��cddd��S#1swxYwYdSr�)rr�r�rjr�r�s  r�r�z_DomainGreaterEqual.__call__ws���
�[��
*�
*�
*�	6�	6��:�a��!4�5�5�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6����	6�	6�	6�	6�	6�	6r�Nr�r�r�r�r�r�ms<��������
-�-�-�6�6�6�6�6r�r�c��eZdZd�Zd�ZdS)�_MaskedUFuncc�D�||_|j|_|j|_dSr)r�r�r�)r}�ufuncs  r�r~z_MaskedUFunc.__init__~s������}������
�
�
r�c��d|j��S)NzMasked version of )r��r}s r��__str__z_MaskedUFunc.__str__�s��,�D�F�,�,�,r�N)r�r�r�r~r�r�r�r�r�r�}s2������'�'�'�
-�-�-�-�-r�r�c�*��eZdZdZd�fd�	Zd�Z�xZS)�_MaskedUnaryOperationa�
    Defines masked version of unary operations, where invalid values are
    pre-masked.

    Parameters
    ----------
    mufunc : callable
        The function for which to define a masked version. Made available
        as ``_MaskedUnaryOperation.f``.
    fill : scalar, optional
        Filling value, default is 0.
    domain : class instance
        Domain for the function. Should be one of the ``_Domain*``
        classes. Default is None.

    rNc���t���|��||_||_|t|<|t
|<dSr)�superr~�fill�domain�ufunc_domain�ufunc_fills)r}�mufuncr�r��	__class__s    �r�r~z_MaskedUnaryOperation.__init__�sC���
������ � � ���	����%��V��"��F���r�c���t|��}|j�tjdd���5|j|g|�Ri|��}ddd��n#1swxYwYtj|��}||�|��z}|t|��z}nNtjdd���5|j|g|�Ri|��}ddd��n#1swxYwYt|��}|js|rtS|S|tur)	tj|||���n#t$rYnwxYw|�
t|����}||_|�|��|S)�-
        Execute the call behavior.

        Nr��rHrr�r�)rXr�rr�r�r�rprYr�rwr��copytor�rlrfrq�_update_from)r}rS�args�kwargs�drUr��
masked_results        r�r�z_MaskedUnaryOperation.__call__�s��

�A�J�J���;�"���H�h�?�?�?�
4�
4�����3�D�3�3�3�F�3�3��
4�
4�
4�
4�
4�
4�
4�
4�
4�
4�
4����
4�
4�
4�
4����'�'�'�A�
����Q����A�
�����O�A�A���H�h�?�?�?�
4�
4�����3�D�3�3�3�F�3�3��
4�
4�
4�
4�
4�
4�
4�
4�
4�
4�
4����
4�
4�
4�
4���
�
�A��{�	��
��
��M��F�?�?�
��	�&�!�1�-�-�-�-�-���
�
�
���
�������$7��$:�$:�;�;�
��
���"�"�1�%�%�%��s5�A�A�A�,C
�
C�C�D�
D%�$D%�rN�r�r�r�r�r~r��
__classcell__�r�s@r�r�r��sV���������"#�#�#�#�#�#�.�.�.�.�.�.�.r�r�c�@��eZdZdZd	�fd�	Zd�Zd
d�Zd�Zdd�Z�xZ	S)�_MaskedBinaryOperationaC
    Define masked version of binary operations, where invalid
    values are pre-masked.

    Parameters
    ----------
    mbfunc : function
        The function for which to define a masked version. Made available
        as ``_MaskedBinaryOperation.f``.
    domain : class instance
        Default domain for the function. Should be one of the ``_Domain*``
        classes. Default is None.
    fillx : scalar, optional
        Filling value for the first argument, default is 0.
    filly : scalar, optional
        Filling value for the second argument, default is 0.

    rc���t���|��||_||_dt|<||ft
|<dS)zr
        abfunc(fillx, filly) must be defined.

        abfunc(x, filly) = x for all x to enable reduce.

        N)r�r~�fillx�fillyr�r�)r}�mbfuncr�r�r�s    �r�r~z_MaskedBinaryOperation.__init__�sI���	������ � � ���
���
�#��V��$�e�n��F���r�c���t|��t|��}}tj��5tjdd���|j||g|�Ri|��}ddd��n#1swxYwYt|��t|��}	}|tur4|	turt}
ndtjt|��|	��}
nA|	tur#tj|t|����}
ntj||	��}
|j
s|
rtS|S|
tur>|
���r*	tj
||d|
���n#t$rYnwxYw|�t!||����}|
|_t%|t&��r|�|��n*t%|t&��r|�|��|S)r�r�r�N�unsafe��castingr�)rXrr��seterrr�rYr�r�rqrZr�rwr!r��	Exceptionrlrfrqr!rr�)r}rSr�r�r��da�dbrU�ma�mbr�r�s            r�r�z_MaskedBinaryOperation.__call__�s"���A�J�J���
�
�R��
�[�]�]�	5�	5��I�X�x�8�8�8�8��T�V�B��4�T�4�4�4�V�4�4�F�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5����	5�	5�	5�	5��A�J�J���
�
�R��
��<�<��V�|�|�����$�\�!�_�_�b�9�9���
�6�\�\�� ��\�!�_�_�5�5�A�A�� ��R�(�(�A��{�	��
��
��M�
�F�?�?�q�u�u�w�w�?�
��	�&�"�h�a�@�@�@�@�@���
�
�
���
�������$7��1�$=�$=�>�>�
��
���a��%�%�	*��&�&�q�)�)�)�)�
��;�
'�
'�	*��&�&�q�)�)�)��s#�)A'�'A+�.A+�>E�
E$�#E$Nc��t|��}t|��}t||j��}|jdkr6|�d��}|turt|d���}d|_|tur#|j�	||��}t}n=|j�	|||���}tj�	||��}|js|rtS|S|�
|��}	||	_|	S)z:
        Reduce `target` along the given `axis`.

        r�r�T�r=�r�r)rfrYrNr�r�r�r�rsr�rr�rorwrlrq)
r}�target�axisr�tclassr��t�tr�mr�	masked_trs
          r�rz_MaskedBinaryOperation.reduce!s���
%�V�,�,���F�O�O���6�4�:�&�&���7�b�=�=��	�	�!���A������a�d�+�+�+�������;�;�����q�$�'�'�B��B�B�����q�$�e��4�4�B��"�)�)�!�T�2�2�B��x�	��
��
��	��G�G�F�O�O�	��	���r�c�*�t|��t|��}}|j�||��}t|��}t|��}|tur|turt}n>t|��}t|��}tj�||��}|js	|rtS|turtj|||���|js|S|�
t||����}	||	_|	S)zO
        Return the function applied to the outer product of a and b.

        r�)rXr�r�rYr�rZr�rqr�rwrr�r�rlrfrq)
r}rSr�r�r�r�r�r�r��masked_ds
          r�r�z_MaskedBinaryOperation.outer?s���
�A�J�J���
�
�R���F�L�L��R� � ��
�Q�Z�Z��
�Q�Z�Z��
��<�<�B�&�L�L��A�A��a���B��a���B�� �&�&�r�2�.�.�A���	�A�	��M��F�?�?��I�a��1�%�%�%�%��w�	��H��6�6�-�a��3�3�4�4������r�c��t|��}t||j��}|j�||��}|�|��}|S)zSAccumulate `target` along `axis` after filling with y fill
        value.

        )rfrNr�r��
accumulaterl)r}r�r�r�r�rUr�s       r�r�z!_MaskedBinaryOperation.accumulateXsP��
%�V�,�,���6�4�:�&�&����"�"�1�d�+�+�����F�+�+�
��r��rrr��r)
r�r�r�r�r~r�rr�r�r�r�s@r�r�r��s����������&-�-�-�-�-�-�-�-�-�^����<���2	�	�	�	�	�	�	�	r�r�c�*��eZdZdZd�fd�	Zd�Z�xZS)�_DomainedBinaryOperationaH
    Define binary operations that have a domain, like divide.

    They have no reduce, outer or accumulate.

    Parameters
    ----------
    mbfunc : function
        The function for which to define a masked version. Made available
        as ``_DomainedBinaryOperation.f``.
    domain : class instance
        Default domain for the function. Should be one of the ``_Domain*``
        classes.
    fillx : scalar, optional
        Filling value for the first argument, default is 0.
    filly : scalar, optional
        Filling value for the second argument, default is 0.

    rc���t���|��||_||_||_|t
|<||ft|<dS)zjabfunc(fillx, filly) must be defined.
           abfunc(x, filly) = x for all x to enable reduce.
        N)r�r~r�r�r�r�r�)r}�dbfuncr�r�r�r�s     �r�r~z!_DomainedBinaryOperation.__init__zsP���	������ � � ������
���
�%��V��$�e�n��F���r�c��t|��t|��}}tjdd���5|j||g|�Ri|��}ddd��n#1swxYwYt	j|��}|t
|��z}|t
|��z}t�|jd��}	|	�||	||��z}|j	s|rtS|S	tj|dd|���t	j||��}
tj
|
j|jd���r||
z
}n#t$rYnwxYw|�t#||����}||_t'|t(��r|�|��n*t'|t(��r|�|��|S)	r�r�r�Nrr�r��safe)r�)rXrr�r�r�rprYr�r*r�rwr�r��can_castrr�rlrfrqr!rr�)r}rSr�r�r�r�r�rUr�r��	masked_dar�s            r�r�z!_DomainedBinaryOperation.__call__�s���A�J�J���
�
�R��
�[��(�
;�
;�
;�	5�	5��T�V�B��4�T�4�4�4�V�4�4�F�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5����	5�	5�	5�	5��^�F�
#�
#�#��	�W�Q�Z�Z���	�W�Q�Z�Z����!�!�$�&�$�/�/����
����B����A��v�	��
��
��
�	��I�f�a���;�;�;�;���q�"�-�-�I��{�9�?�F�L�&�I�I�I�
$��)�#�����	�	�	��D�	�������$7��1�$=�$=�>�>�
��
���a��%�%�	*��&�&�q�)�)�)�)�
��;�
'�
'�	*��&�&�q�)�)�)��s$�A�A�A�AD0�0
D=�<D=r�r�r�s@r�r�r�esV���������(	-�	-�	-�	-�	-�	-�(�(�(�(�(�(�(r�r����?gz�����8g�g�������g�������?r�c���t}|j�rg}|jD]S}|j|}t|��dkr
|d|f}|�|||d|��f���Ttj|��}nY|jrPt|j��}||jd|��|d<tjt|����}n|}||kr|}|S)z=Private function allowing recursion in _replace_dtype_fields.Nr�r�r)
�_replace_dtype_fields_recursiver�fieldsr<r"rrrrur)r�primitive_dtype�_recurse�descrr�field�	new_dtypes       r�r�r�s���.�H�
�{�����K�	F�	F�D��L��&�E��5�z�z�Q����b�	�4�(���L�L�$����q��?� C� C�D�E�E�E�E��H�U�O�O�	�	�
��$��U�^�$�$���8�E�N�1�-��?�?��a���H�U�5�\�\�*�*�	�	�$�	��E����	��r�c�r�tj|��}tj|��}t||��S)z�
    Construct a dtype description list from a given dtype.

    Returns a new dtype object, with all fields and subtypes in the given type
    recursively replaced with `primitive_dtype`.

    Arguments are coerced to dtypes first.
    )rrr�)rr�s  r��_replace_dtype_fieldsr�#s0��
�H�U�O�O�E��h��/�/�O�*�5�/�B�B�Br�c�,�t|t��S)a�
    Construct a dtype description list from a given dtype.

    Returns a new dtype object, with the type of all fields in `ndtype` to a
    boolean type. Field names are not altered.

    Parameters
    ----------
    ndtype : dtype
        The dtype to convert.

    Returns
    -------
    result : dtype
        A dtype that looks like `ndtype`, the type of all fields is boolean.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> dtype = np.dtype({'names':['foo', 'bar'],
    ...                   'formats':[np.float32, np.int64]})
    >>> dtype
    dtype([('foo', '<f4'), ('bar', '<i8')])
    >>> ma.make_mask_descr(dtype)
    dtype([('foo', '|b1'), ('bar', '|b1')])
    >>> ma.make_mask_descr(np.float32)
    dtype('bool')

    )r�r)rNs r�rtrt1s��<!���2�2�2r�c�.�t|dt��S)a
    Return the mask of a masked array, or nomask.

    Return the mask of `a` as an ndarray if `a` is a `MaskedArray` and the
    mask is not `nomask`, else return `nomask`. To guarantee a full array
    of booleans of the same shape as a, use `getmaskarray`.

    Parameters
    ----------
    a : array_like
        Input `MaskedArray` for which the mask is required.

    See Also
    --------
    getdata : Return the data of a masked array as an ndarray.
    getmaskarray : Return the mask of a masked array, or full array of False.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = ma.masked_equal([[1,2],[3,4]], 2)
    >>> a
    masked_array(
      data=[[1, --],
            [3, 4]],
      mask=[[False,  True],
            [False, False]],
      fill_value=2)
    >>> ma.getmask(a)
    array([[False,  True],
           [False, False]])

    Equivalently use the `MaskedArray` `mask` attribute.

    >>> a.mask
    array([[False,  True],
           [False, False]])

    Result when mask == `nomask`

    >>> b = ma.masked_array([[1,2],[3,4]])
    >>> b
    masked_array(
      data=[[1, 2],
            [3, 4]],
      mask=False,
      fill_value=999999)
    >>> ma.nomask
    False
    >>> ma.getmask(b) == ma.nomask
    True
    >>> b.mask == ma.nomask
    True

    rq)�getattrr�)rSs r�rYrYRs��p�1�g�v�&�&�&r�c��t|��}|tur1ttj|��t|dd����}|S)ae
    Return the mask of a masked array, or full boolean array of False.

    Return the mask of `arr` as an ndarray if `arr` is a `MaskedArray` and
    the mask is not `nomask`, else return a full boolean array of False of
    the same shape as `arr`.

    Parameters
    ----------
    arr : array_like
        Input `MaskedArray` for which the mask is required.

    See Also
    --------
    getmask : Return the mask of a masked array, or nomask.
    getdata : Return the data of a masked array as an ndarray.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = ma.masked_equal([[1,2],[3,4]], 2)
    >>> a
    masked_array(
      data=[[1, --],
            [3, 4]],
      mask=[[False,  True],
            [False, False]],
      fill_value=2)
    >>> ma.getmaskarray(a)
    array([[False,  True],
           [False, False]])

    Result when mask == ``nomask``

    >>> b = ma.masked_array([[1,2],[3,4]])
    >>> b
    masked_array(
      data=[[1, 2],
            [3, 4]],
      mask=False,
      fill_value=999999)
    >>> ma.getmaskarray(b)
    array([[False, False],
           [False, False]])

    rN)rYr�rurr�r�)r�ros  r�rZrZ�sA��^�3�<�<�D��v�~�~��b�h�s�m�m�W�S�'�4�-H�-H�I�I���Kr�c�L�	|jjtuS#t$rYdSwxYw)a)
    Return True if m is a valid, standard mask.

    This function does not check the contents of the input, only that the
    type is MaskType. In particular, this function returns False if the
    mask has a flexible dtype.

    Parameters
    ----------
    m : array_like
        Array to test.

    Returns
    -------
    result : bool
        True if `m.dtype.type` is MaskType, False otherwise.

    See Also
    --------
    ma.isMaskedArray : Test whether input is an instance of MaskedArray.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> m = ma.masked_equal([0, 1, 0, 2, 3], 0)
    >>> m
    masked_array(data=[--, 1, --, 2, 3],
                 mask=[ True, False,  True, False, False],
           fill_value=0)
    >>> ma.is_mask(m)
    False
    >>> ma.is_mask(m.mask)
    True

    Input must be an ndarray (or have similar attributes)
    for it to be considered a valid mask.

    >>> m = [False, True, False]
    >>> ma.is_mask(m)
    False
    >>> m = np.array([False, True, False])
    >>> m
    array([False,  True, False])
    >>> ma.is_mask(m)
    True

    Arrays with complex dtypes don't return True.

    >>> dtype = np.dtype({'names':['monty', 'pithon'],
    ...                   'formats':[bool, bool]})
    >>> dtype
    dtype([('monty', '|b1'), ('pithon', '|b1')])
    >>> m = np.array([(True, False), (False, True), (True, False)],
    ...              dtype=dtype)
    >>> m
    array([( True, False), (False,  True), ( True, False)],
          dtype=[('monty', '?'), ('pithon', '?')])
    >>> ma.is_mask(m)
    False

    F)rr^rrk�r�s r�rfrf�s9��|��w�|�x�'�'�������u�u����s��
#�#c�T�|jj�|���stS|S)z-
    Shrink a mask to nomask if possible
    )rrr!r�r�s r��_shrink_maskr�	s%��	�w�}��Q�U�U�W�W���
��r�Fc�J�|turtSt|��}t|t��r7|jjr+|tjkrt
j|j	|���St
j
t|d��||d���}|rt|��}|S)a�
    Create a boolean mask from an array.

    Return `m` as a boolean mask, creating a copy if necessary or requested.
    The function can accept any sequence that is convertible to integers,
    or ``nomask``.  Does not require that contents must be 0s and 1s, values
    of 0 are interpreted as False, everything else as True.

    Parameters
    ----------
    m : array_like
        Potential mask.
    copy : bool, optional
        Whether to return a copy of `m` (True) or `m` itself (False).
    shrink : bool, optional
        Whether to shrink `m` to ``nomask`` if all its values are False.
    dtype : dtype, optional
        Data-type of the output mask. By default, the output mask has a
        dtype of MaskType (bool). If the dtype is flexible, each field has
        a boolean dtype. This is ignored when `m` is ``nomask``, in which
        case ``nomask`` is always returned.

    Returns
    -------
    result : ndarray
        A boolean mask derived from `m`.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> m = [True, False, True, True]
    >>> ma.make_mask(m)
    array([ True, False,  True,  True])
    >>> m = [1, 0, 1, 1]
    >>> ma.make_mask(m)
    array([ True, False,  True,  True])
    >>> m = [1, 0, 2, -3]
    >>> ma.make_mask(m)
    array([ True, False,  True,  True])

    Effect of the `shrink` parameter.

    >>> m = np.zeros(4)
    >>> m
    array([0., 0., 0., 0.])
    >>> ma.make_mask(m)
    False
    >>> ma.make_mask(m, shrink=False)
    array([False, False, False, False])

    Using a flexible `dtype`.

    >>> m = [1, 0, 1, 1]
    >>> n = [0, 1, 0, 0]
    >>> arr = []
    >>> for man, mouse in zip(m, n):
    ...     arr.append((man, mouse))
    >>> arr
    [(1, 0), (0, 1), (1, 0), (1, 0)]
    >>> dtype = np.dtype({'names':['man', 'mouse'],
    ...                   'formats':[np.int64, np.int64]})
    >>> arr = np.array(arr, dtype=dtype)
    >>> arr
    array([(1, 0), (0, 1), (1, 0), (1, 0)],
          dtype=[('man', '<i8'), ('mouse', '<i8')])
    >>> ma.make_mask(arr, dtype=dtype)
    array([(True, False), (False, True), (True, False), (True, False)],
          dtype=[('man', '|b1'), ('mouse', '|b1')])

    rT)r=rri)
r�rtr!rrr�rr	r�r�rrNr�)r�r=�shrinkrrUs     r�rsrss���N	�F�{�{��
�
�E�"�"�E��!�W���-�!�'�.�-�U�b�h�5F�5F��w�q�w�e�,�,�,�,��X�f�Q��o�o�D��T�
J�
J�
J�F�
�&��f�%�%���Mr�c��|�tj|t���}n#tj|t|�����}|S)a&
    Return a boolean mask of the given shape, filled with False.

    This function returns a boolean ndarray with all entries False, that can
    be used in common mask manipulations. If a complex dtype is specified, the
    type of each field is converted to a boolean type.

    Parameters
    ----------
    newshape : tuple
        A tuple indicating the shape of the mask.
    dtype : {None, dtype}, optional
        If None, use a MaskType instance. Otherwise, use a new datatype with
        the same fields as `dtype`, converted to boolean types.

    Returns
    -------
    result : ndarray
        An ndarray of appropriate shape and dtype, filled with False.

    See Also
    --------
    make_mask : Create a boolean mask from an array.
    make_mask_descr : Construct a dtype description list from a given dtype.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> ma.make_mask_none((3,))
    array([False, False, False])

    Defining a more complex dtype.

    >>> dtype = np.dtype({'names':['foo', 'bar'],
    ...                   'formats':[np.float32, np.int64]})
    >>> dtype
    dtype([('foo', '<f4'), ('bar', '<i8')])
    >>> ma.make_mask_none((3,), dtype=dtype)
    array([(False, False), (False, False), (False, False)],
          dtype=[('foo', '|b1'), ('bar', '|b1')])

    Nr)rr�rrt)�newshaperrUs   r�rurulsA��V
�}���(�(�3�3�3�����(�/�%�*@�*@�A�A�A���Mr�c���|jj}|D]V}||}|jj�t|||||���4tj|||||���WdSr)rr�_recursive_mask_orr�rq)�m1�m2�newmaskrr�current1s      r�rr�sy���H�N�E��@�@���d�8���>��+��x��D��7�4�=�A�A�A�A���X�r�$�x����?�?�?�?�@�@r�c�X�|tus|dur)t|dt��}t||||���S|tus|dur)t|dt��}t||||���S||urt	|��r|St|dd��t|dd��}}||krtd|�d|�d����|j�@tjtj	||��j
|��}t|||��|Sttj
||��||���S)	a�
    Combine two masks with the ``logical_or`` operator.

    The result may be a view on `m1` or `m2` if the other is `nomask`
    (i.e. False).

    Parameters
    ----------
    m1, m2 : array_like
        Input masks.
    copy : bool, optional
        If copy is False and one of the inputs is `nomask`, return a view
        of the other input mask. Defaults to False.
    shrink : bool, optional
        Whether to shrink the output to `nomask` if all its values are
        False. Defaults to True.

    Returns
    -------
    mask : output mask
        The result masks values that are masked in either `m1` or `m2`.

    Raises
    ------
    ValueError
        If `m1` and `m2` have different flexible dtypes.

    Examples
    --------
    >>> m1 = np.ma.make_mask([0, 1, 1, 0])
    >>> m2 = np.ma.make_mask([1, 0, 0, 0])
    >>> np.ma.mask_or(m1, m2)
    array([ True,  True,  True, False])

    Fr)r=rrNzIncompatible dtypes 'z'<>'�'�r=r)r�r�rrsrfrIrrrI�	broadcastr�rr�rq)rrr=rr�dtype1�dtype2rs        r�rvrv�s9��J	�f���"��+�+���G�X�.�.����$�v�U�C�C�C�C�
�f���"��+�+���G�X�.�.����$�v�U�C�C�C�C�	�R�x�x�G�B�K�K�x��	���G�T�2�2�G�B���4N�4N�V�V�
�����j�V�V�V�V�V�V�L�M�M�M�
�|���(�2�<��B�/�/�5�v�>�>���2�r�7�+�+�+����U�%�b�"�-�-�D��H�H�H�Hr�c���d�}�fd��tj|��}�||����}tjd�|D��t���S)a&
    Returns a completely flattened version of the mask, where nested fields
    are collapsed.

    Parameters
    ----------
    mask : array_like
        Input array, which will be interpreted as booleans.

    Returns
    -------
    flattened_mask : ndarray of bools
        The flattened input.

    Examples
    --------
    >>> mask = np.array([0, 0, 1])
    >>> np.ma.flatten_mask(mask)
    array([False, False,  True])

    >>> mask = np.array([(0, 0), (0, 1)], dtype=[('a', bool), ('b', bool)])
    >>> np.ma.flatten_mask(mask)
    array([False, False, False,  True])

    >>> mdtype = [('a', bool), ('b', [('ba', bool), ('bb', bool)])]
    >>> mask = np.array([(0, (0, 0)), (0, (0, 1))], dtype=mdtype)
    >>> np.ma.flatten_mask(mask)
    array([False, False, False, False, False,  True])

    c�@���jj}|��fd�|D��S�S)zCFlatten the mask and returns a (maybe nested) sequence of booleans.Nc�:��g|]}t�|����Sr�)rP)rrros  �r�rz3flatten_mask.<locals>._flatmask.<locals>.<listcomp>s%���@�@�@��L��d��,�,�@�@�@r��rr)ro�mnamess` r��	_flatmaskzflatten_mask.<locals>._flatmasks2�����!����@�@�@�@��@�@�@�@��Kr�c3��K�	|D](}t|d��r�|��Ed{V���$|V��)dS#t$r|V�YdSwxYw)z.Generates a flattened version of the sequence.�__iter__N)r"r�)�sequence�element�
_flatsequences  �r�rz#flatten_mask.<locals>._flatsequences������	�#�
"�
"���7�J�/�/�"�,�}�W�5�5�5�5�5�5�5�5�5�5�!�M�M�M�M�	
"�
"��
�	�	�	��N�N�N�N�N�N�	���s�+2�A�Ac��g|]}|��Sr�r��r�_s  r�rz flatten_mask.<locals>.<listcomp>s��*�*�*�1�Q�*�*�*r�r)rr0r�bool)ror�	flattenedrs   @r�rPrP�sx���@���	�	�	�	�	��:�d���D��
�i�i��o�o�.�.�I�
�8�*�*�	�*�*�*�$�7�7�7�7r�c�h�|tjurind|i}|tur|jdd|i|��StS)z:Check whether there are masked values along the given axis�keepdimsr�r�)rr
r�r)ror�r!r�s    r��_check_mask_axisr"sI���r�{�*�*�R�R��X�0F�F��6����t�x�,�,�T�,�V�,�,�,��Mr�c��t|d���}tj||d���}|j|j}}|r||krt	d|�d|�d����t|d��r%t
||j��}t|��}nt}|�
|��}t|��|_|sDt|d��r4t|��tur|j�
��|_|S)	a�
    Mask an array where a condition is met.

    Return `a` as an array masked where `condition` is True.
    Any masked values of `a` or `condition` are also masked in the output.

    Parameters
    ----------
    condition : array_like
        Masking condition.  When `condition` tests floating point values for
        equality, consider using ``masked_values`` instead.
    a : array_like
        Array to mask.
    copy : bool
        If True (default) make a copy of `a` in the result.  If False modify
        `a` in place and return a view.

    Returns
    -------
    result : MaskedArray
        The result of masking `a` where `condition` is True.

    See Also
    --------
    masked_values : Mask using floating point equality.
    masked_equal : Mask where equal to a given value.
    masked_not_equal : Mask where `not` equal to a given value.
    masked_less_equal : Mask where less than or equal to a given value.
    masked_greater_equal : Mask where greater than or equal to a given value.
    masked_less : Mask where less than a given value.
    masked_greater : Mask where greater than a given value.
    masked_inside : Mask inside a given interval.
    masked_outside : Mask outside a given interval.
    masked_invalid : Mask invalid values (NaNs or infs).

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.arange(4)
    >>> a
    array([0, 1, 2, 3])
    >>> ma.masked_where(a <= 2, a)
    masked_array(data=[--, --, --, 3],
                 mask=[ True,  True,  True, False],
           fill_value=999999)

    Mask array `b` conditional on `a`.

    >>> b = ['a', 'b', 'c', 'd']
    >>> ma.masked_where(a == 2, b)
    masked_array(data=['a', 'b', --, 'd'],
                 mask=[False, False,  True, False],
           fill_value='N/A',
                dtype='<U1')

    Effect of the `copy` argument.

    >>> c = ma.masked_where(a <= 2, a)
    >>> c
    masked_array(data=[--, --, --, 3],
                 mask=[ True,  True,  True, False],
           fill_value=999999)
    >>> c[0] = 99
    >>> c
    masked_array(data=[99, --, --, 3],
                 mask=[False,  True,  True, False],
           fill_value=999999)
    >>> a
    array([0, 1, 2, 3])
    >>> c = ma.masked_where(a <= 2, a, copy=False)
    >>> c[0] = 99
    >>> c
    masked_array(data=[99, --, --, 3],
                 mask=[False,  True,  True, False],
           fill_value=999999)
    >>> a
    array([99,  1,  2,  3])

    When `condition` or `a` contain masked values.

    >>> a = np.arange(4)
    >>> a = ma.masked_where(a == 2, a)
    >>> a
    masked_array(data=[0, 1, --, 3],
                 mask=[False, False,  True, False],
           fill_value=999999)
    >>> b = np.arange(4)
    >>> b = ma.masked_where(b == 0, b)
    >>> b
    masked_array(data=[--, 1, 2, 3],
                 mask=[ True, False, False, False],
           fill_value=999999)
    >>> ma.masked_where(a == 3, b)
    masked_array(data=[--, 1, --, --],
                 mask=[ True, False,  True,  True],
           fill_value=999999)

    F�rTrhz<Inconsistent shape between the condition and the input (got z and �)rq)rsrrr��
IndexErrorr"rvrqr^rrlr�rorYr�)�	conditionrSr=�cond�cshape�ashapererUs        r�r�r�$s��H�Y�u�-�-�-�D�
����T�*�*�*�A��
�A�G�V�V�
�@�&�F�"�"��j�/5�v�v�v�v�v�?�@�@�	@��q�'�����t�Q�W�%�%���1�g�g�����
�V�V�C�[�[�F��t�$�$�F�K��&�G�A�w�'�'�&�G�A�J�J�&�,@�,@��,�#�#�%�%����Mr�c�B�tt||��||���S)a�
    Mask an array where greater than a given value.

    This function is a shortcut to ``masked_where``, with
    `condition` = (x > value).

    See Also
    --------
    masked_where : Mask where a condition is met.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.arange(4)
    >>> a
    array([0, 1, 2, 3])
    >>> ma.masked_greater(a, 2)
    masked_array(data=[0, 1, 2, --],
                 mask=[False, False, False,  True],
           fill_value=999999)

    r�)r�r[�r��valuer=s   r�rzrz�s#��.���5�)�)�1�4�8�8�8�8r�c�B�tt||��||���S)a
    Mask an array where greater than or equal to a given value.

    This function is a shortcut to ``masked_where``, with
    `condition` = (x >= value).

    See Also
    --------
    masked_where : Mask where a condition is met.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.arange(4)
    >>> a
    array([0, 1, 2, 3])
    >>> ma.masked_greater_equal(a, 2)
    masked_array(data=[0, 1, --, --],
                 mask=[False, False,  True,  True],
           fill_value=999999)

    r�)r�r\r,s   r�r{r{�s#��.�
�a��/�/���>�>�>�>r�c�B�tt||��||���S)a�
    Mask an array where less than a given value.

    This function is a shortcut to ``masked_where``, with
    `condition` = (x < value).

    See Also
    --------
    masked_where : Mask where a condition is met.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.arange(4)
    >>> a
    array([0, 1, 2, 3])
    >>> ma.masked_less(a, 2)
    masked_array(data=[--, --, 2, 3],
                 mask=[ True,  True, False, False],
           fill_value=999999)

    r�)r�rjr,s   r�r~r~�s!��.��Q������5�5�5�5r�c�B�tt||��||���S)a�
    Mask an array where less than or equal to a given value.

    This function is a shortcut to ``masked_where``, with
    `condition` = (x <= value).

    See Also
    --------
    masked_where : Mask where a condition is met.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.arange(4)
    >>> a
    array([0, 1, 2, 3])
    >>> ma.masked_less_equal(a, 2)
    masked_array(data=[--, --, --, 3],
                 mask=[ True,  True,  True, False],
           fill_value=999999)

    r�)r�rkr,s   r�rr�s#��.�
�1�e�,�,�a�d�;�;�;�;r�c�B�tt||��||���S)a�
    Mask an array where `not` equal to a given value.

    This function is a shortcut to ``masked_where``, with
    `condition` = (x != value).

    See Also
    --------
    masked_where : Mask where a condition is met.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.arange(4)
    >>> a
    array([0, 1, 2, 3])
    >>> ma.masked_not_equal(a, 2)
    masked_array(data=[--, --, 2, --],
                 mask=[ True,  True, False,  True],
           fill_value=999999)

    r�)r�r�r,s   r�r�r�s#��.�	�!�U�+�+�Q�T�:�:�:�:r�c�T�tt||��||���}||_|S)a�
    Mask an array where equal to a given value.

    Return a MaskedArray, masked where the data in array `x` are
    equal to `value`. The fill_value of the returned MaskedArray
    is set to `value`.

    For floating point arrays, consider using ``masked_values(x, value)``.

    See Also
    --------
    masked_where : Mask where a condition is met.
    masked_values : Mask using floating point equality.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.arange(4)
    >>> a
    array([0, 1, 2, 3])
    >>> ma.masked_equal(a, 2)
    masked_array(data=[0, 1, --, 3],
                 mask=[False, False,  True, False],
           fill_value=2)

    r�)r�rKrM)r�r-r=�outputs    r�ryry s-��6�%��5�/�/�1�4�
8�
8�
8�F��F���Mr�c�r�||kr||}}t|��}||k||kz}t|||���S)a�
    Mask an array inside a given interval.

    Shortcut to ``masked_where``, where `condition` is True for `x` inside
    the interval [v1,v2] (v1 <= x <= v2).  The boundaries `v1` and `v2`
    can be given in either order.

    See Also
    --------
    masked_where : Mask where a condition is met.

    Notes
    -----
    The array `x` is prefilled with its filling value.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> x = [0.31, 1.2, 0.01, 0.2, -0.4, -1.1]
    >>> ma.masked_inside(x, -0.3, 0.3)
    masked_array(data=[0.31, 1.2, --, --, -0.4, -1.1],
                 mask=[False, False,  True,  True, False, False],
           fill_value=1e+20)

    The order of `v1` and `v2` doesn't matter.

    >>> ma.masked_inside(x, 0.3, -0.3)
    masked_array(data=[0.31, 1.2, --, --, -0.4, -1.1],
                 mask=[False, False,  True,  True, False, False],
           fill_value=1e+20)

    r��rNr��r��v1�v2r=�xfr's      r�r|r|@sI��B
�B�w�w���R��	����B��r��b�B�h�'�I��	�1�4�0�0�0�0r�c�r�||kr||}}t|��}||k||kz}t|||���S)a�
    Mask an array outside a given interval.

    Shortcut to ``masked_where``, where `condition` is True for `x` outside
    the interval [v1,v2] (x < v1)|(x > v2).
    The boundaries `v1` and `v2` can be given in either order.

    See Also
    --------
    masked_where : Mask where a condition is met.

    Notes
    -----
    The array `x` is prefilled with its filling value.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> x = [0.31, 1.2, 0.01, 0.2, -0.4, -1.1]
    >>> ma.masked_outside(x, -0.3, 0.3)
    masked_array(data=[--, --, 0.01, 0.2, --, --],
                 mask=[ True,  True, False, False,  True,  True],
           fill_value=1e+20)

    The order of `v1` and `v2` doesn't matter.

    >>> ma.masked_outside(x, 0.3, -0.3)
    masked_array(data=[--, --, 0.01, 0.2, --, --],
                 mask=[ True,  True, False, False,  True,  True],
           fill_value=1e+20)

    r�r5r6s      r�r�r�hsI��B
�B�w�w���R��	����B��b��R�"�W�%�I��	�1�4�0�0�0�0r�c�$�t|��r"tj|j|��}|j}n.tjtj|��|��}t}t|t||�����}t||||���S)a�
    Mask the array `x` where the data are exactly equal to value.

    This function is similar to `masked_values`, but only suitable
    for object arrays: for floating point, use `masked_values` instead.

    Parameters
    ----------
    x : array_like
        Array to mask
    value : object
        Comparison value
    copy : {True, False}, optional
        Whether to return a copy of `x`.
    shrink : {True, False}, optional
        Whether to collapse a mask full of False to nomask

    Returns
    -------
    result : MaskedArray
        The result of masking `x` where equal to `value`.

    See Also
    --------
    masked_where : Mask where a condition is met.
    masked_equal : Mask where equal to a given value (integers).
    masked_values : Mask using floating point equality.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> food = np.array(['green_eggs', 'ham'], dtype=object)
    >>> # don't eat spoiled food
    >>> eat = ma.masked_object(food, 'green_eggs')
    >>> eat
    masked_array(data=[--, 'ham'],
                 mask=[ True, False],
           fill_value='green_eggs',
                dtype=object)
    >>> # plain ol` ham is boring
    >>> fresh_food = np.array(['cheese', 'ham', 'pineapple'], dtype=object)
    >>> eat = ma.masked_object(fresh_food, 'green_eggs')
    >>> eat
    masked_array(data=['cheese', 'ham', 'pineapple'],
                 mask=False,
           fill_value='green_eggs',
                dtype=object)

    Note that `mask` is set to ``nomask`` if possible.

    >>> eat
    masked_array(data=['cheese', 'ham', 'pineapple'],
                 mask=False,
           fill_value='green_eggs',
                dtype=object)

    r$�ror=rM)rer�rKrjrqrr0r�rvrsrx)r�r-r=rr'ros      r�r�r��s���t�Q�����K����/�/�	��w����K��
�1�
�
�u�5�5�	����4��9�V�<�<�<�=�=�D����4�E�B�B�B�Br���h㈵��>�:�0�yE>c��t||��}tj|jtj��rtj||||���}nt
j||��}t||||���}|r|�	��|S)a�
    Mask using floating point equality.

    Return a MaskedArray, masked where the data in array `x` are approximately
    equal to `value`, determined using `isclose`. The default tolerances for
    `masked_values` are the same as those for `isclose`.

    For integer types, exact equality is used, in the same way as
    `masked_equal`.

    The fill_value is set to `value` and the mask is set to ``nomask`` if
    possible.

    Parameters
    ----------
    x : array_like
        Array to mask.
    value : float
        Masking value.
    rtol, atol : float, optional
        Tolerance parameters passed on to `isclose`
    copy : bool, optional
        Whether to return a copy of `x`.
    shrink : bool, optional
        Whether to collapse a mask full of False to ``nomask``.

    Returns
    -------
    result : MaskedArray
        The result of masking `x` where approximately equal to `value`.

    See Also
    --------
    masked_where : Mask where a condition is met.
    masked_equal : Mask where equal to a given value (integers).

    Examples
    --------
    >>> import numpy.ma as ma
    >>> x = np.array([1, 1.1, 2, 1.1, 3])
    >>> ma.masked_values(x, 1.1)
    masked_array(data=[1.0, --, 2.0, --, 3.0],
                 mask=[False,  True, False,  True, False],
           fill_value=1.1)

    Note that `mask` is set to ``nomask`` if possible.

    >>> ma.masked_values(x, 2.1)
    masked_array(data=[1. , 1.1, 2. , 1.1, 3. ],
                 mask=False,
           fill_value=2.1)

    Unlike `masked_equal`, `masked_values` can perform approximate equalities.

    >>> ma.masked_values(x, 2.1, atol=1e-1)
    masked_array(data=[1.0, 1.1, --, 1.1, 3.0],
                 mask=[False, False,  True, False, False],
           fill_value=2.1)

    )�atol�rtolr<)
rNr�
issubdtyper�floating�iscloser�rKrx�shrink_mask)	r�r-rAr@r=r�xnewro�rets	         r�r�r��s���z�!�U���D�	�}�T�Z���-�-�(��z�$��D�t�<�<�<����{�4��'�'��
�t�$�T�e�
D�
D�
D�C�
���������Jr�c���tj|dd���}ttj|��||���}|jt
urt
|j|j��|_|S)a�
    Mask an array where invalid values occur (NaNs or infs).

    This function is a shortcut to ``masked_where``, with
    `condition` = ~(np.isfinite(a)). Any pre-existing mask is conserved.
    Only applies to arrays with a dtype where NaNs or infs make sense
    (i.e. floating point types), but accepts any array_like object.

    See Also
    --------
    masked_where : Mask where a condition is met.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.arange(5, dtype=float)
    >>> a[2] = np.NaN
    >>> a[3] = np.PINF
    >>> a
    array([ 0.,  1., nan, inf,  4.])
    >>> ma.masked_invalid(a)
    masked_array(data=[0.0, 1.0, --, --, 4.0],
                 mask=[False, False,  True,  True, False],
           fill_value=1e+20)

    FTrhr�)	rrr�rprqr�rur�r)rSr=�ress   r�r}r}	sb��6	����d�+�+�+�A�
���Q���(�!�$�
7�
7�
7�C��y�F���"�3�9�c�i�8�8��	��Jr�c�<�eZdZdZd�Zd�Zd�Zd�Zd
d�Zd�Z	e	Z
d	S)�_MaskedPrintOptionzN
    Handle the string used to represent missing data in a masked array.

    c�"�||_d|_dS)z9
        Create the masked_print_option object.

        TN)�_display�_enabled)r}�displays  r�r~z_MaskedPrintOption.__init__J	s��
 ��
���
�
�
r�c��|jS)zA
        Display the string to print for masked values.

        �rMr�s r�rOz_MaskedPrintOption.displayR	���
�}�r�c��||_dS)z=
        Set the string to print for masked values.

        NrQ)r}r�s  r��set_displayz_MaskedPrintOption.set_displayY	s��
��
�
�
r�c��|jS)z;
        Is the use of the display value enabled?

        �rNr�s r��enabledz_MaskedPrintOption.enabled`	rRr�r�c��||_dS)z7
        Set the enabling shrink to `shrink`.

        NrV)r}rs  r��enablez_MaskedPrintOption.enableg	s��
��
�
�
r�c�*�t|j��Sr)r+rMr�s r�r�z_MaskedPrintOption.__str__n	s���4�=�!�!�!r�Nr�)r�r�r�r�r~rOrTrWrYr��__repr__r�r�r�rKrKD	s~��������
����������������"�"�"��H�H�Hr�rKz--c��|jj}|�'|D]#}||}||}t|||���$ntj|||���dS)zg
    Puts printoptions in result where mask is True.

    Private function allowing for recursion

    Nr�)rr�_recursive_printoptionrr�)rUro�printoptrr�curdata�curmasks       r�r]r]w	sm��
�L��E����	?�	?�D��T�l�G��4�j�G�"�7�G�X�>�>�>�>�	?�
	�	�&�(�$�/�/�/�/�
�Fr�z�        masked_%(name)s(data =
         %(data)s,
        %(nlen)s        mask =
         %(mask)s,
        %(nlen)s  fill_value = %(fill)s)
        z�        masked_%(name)s(data =
         %(data)s,
        %(nlen)s        mask =
         %(mask)s,
        %(nlen)s  fill_value = %(fill)s,
        %(nlen)s       dtype = %(dtype)s)
        z�        masked_%(name)s(data = %(data)s,
        %(nlen)s        mask = %(mask)s,
        %(nlen)s  fill_value = %(fill)s)
        z�        masked_%(name)s(data = %(data)s,
        %(nlen)s        mask = %(mask)s,
        %(nlen)s  fill_value = %(fill)s,
        %(nlen)s       dtype = %(dtype)s)
        )�long_std�long_flx�	short_std�	short_flxc���|jj}|D]W}||}|jj�t|||||���4tj|||||����XdS)z2
    Recursively fill `a` with `fill_value`.

    Nr�)rr�_recursive_filledrr�)rSrorMrr�currents      r�rfrf�	s��

�G�M�E��C�C���D�'���=��*��g�t�D�z�:�d�3C�D�D�D�D��I�g�z�$�/�t�D�z�B�B�B�B�B�C�Cr�c�P���fd��tj|��}|j}|���}t	|t
��rrtj�fd�|jD����}|�t
��}tj�fd�t|��D����|_
n tj�fd�|D����}t|��dkr6t|j��}||d<t�|����|_|S)a:
    Flatten a structured array.

    The data type of the output is chosen such that it can represent all of the
    (nested) fields.

    Parameters
    ----------
    a : structured array

    Returns
    -------
    output : masked array or ndarray
        A flattened masked array if the input is a masked array, otherwise a
        standard ndarray.

    Examples
    --------
    >>> ndtype = [('a', int), ('b', float)]
    >>> a = np.array([(1, 1), (2, 2)], dtype=ndtype)
    >>> np.ma.flatten_structured_array(a)
    array([[1., 1.],
           [2., 2.]])

    c3�|�K�t|��D](}t|d��r�|��Ed{V���$|V��)dS)z;
        Flattens a compound of nested iterables.

        rN)�iterr")�iterable�elm�flatten_sequences  �r�rmz2flatten_structured_array.<locals>.flatten_sequence�	sk�����
��>�>�	�	�C��s�J�'�'�
�+�+�C�0�0�0�0�0�0�0�0�0�0��	�	�	�	�		�	r�c�d��g|],}t�|���������-Sr��rr?�rr�rms  �r�rz,flatten_structured_array.<locals>.<listcomp>�	s5���K�K�K�a��.�.�q�v�v�x�x�8�8�9�9�K�K�Kr�c�d��g|],}t�|���������-Sr�rorps  �r�rz,flatten_structured_array.<locals>.<listcomp>�	sE���8�8�8�"#�$�$4�$4�Q�V�V�X�X�$>�$>�?�?�8�8�8r�c�d��g|],}t�|���������-Sr�rorps  �r�rz,flatten_structured_array.<locals>.<listcomp>�	s5���E�E�E�a��.�.�q�v�v�x�x�8�8�9�9�E�E�Er�r�r)rr/r�r�r!rrrjrlrZrqr<rur)rS�inishape�outrrms    @r�rQrQ�	s9���6	�	�	�	�	�	�
�a���A��w�H�	���	�	�A��!�[�!�!�G��h�K�K�K�K�1�7�K�K�K�L�L���h�h�{�#�#���H�8�8�8�8�'3�A���8�8�8�9�9��	�	��h�E�E�E�E�1�E�E�E�F�F��
�8�}�}�q�����	�?�?�������*�*�8�4�4�5�5��	��Jr�c������fd�}tt�d��ptt�d��}|�|j|_�|_|S)a
    Return a class method wrapper around a basic array method.

    Creates a class method which returns a masked array, where the new
    ``_data`` array is the output of the corresponding basic method called
    on the original ``_data``.

    If `onmask` is True, the new mask is the output of the method called
    on the initial mask. Otherwise, the new mask is just a reference
    to the initial mask.

    Parameters
    ----------
    funcname : str
        Name of the function to apply on data.
    onmask : bool
        Whether the mask must be processed also (True) or left
        alone (False). Default is True. Make available as `_onmask`
        attribute.

    Returns
    -------
    method : instancemethod
        Class method wrapper of the specified basic array method.

    c�2��t|j���|i|��}|�t|����}|�|��|j}�s|�|��n$|turt|���|i|��|_|Sr)r�rjrlr^r�rq�__setmask__r�)r}r��paramsrUro�funcname�onmasks     ��r��wrapped_methodz$_arraymethod.<locals>.wrapped_method
s����.����X�.�.��?��?�?�����T�$�Z�Z�(�(�����D�!�!�!��z���	D����t�$�$�$�$�
��
�
�2�7�4��2�2�D�C�F�C�C�F�L��
r�N)r�rrr�r�)ryrzr{�methdocs``  r��_arraymethodr}�	sd����6
�
�
�
�
�
��g�x��.�.�M�'�"�h��2M�2M�G���!(����&�N���r�c�0�eZdZdZd�Zd�Zd�Zd�Zd�ZdS)�MaskedIteratora�
    Flat iterator object to iterate over masked arrays.

    A `MaskedIterator` iterator is returned by ``x.flat`` for any masked array
    `x`. It allows iterating over the array as if it were a 1-D array,
    either in a for-loop or by calling its `next` method.

    Iteration is done in C-contiguous style, with the last index varying the
    fastest. The iterator can also be indexed using basic slicing or
    advanced indexing.

    See Also
    --------
    MaskedArray.flat : Return a flat iterator over an array.
    MaskedArray.flatten : Returns a flattened copy of an array.

    Notes
    -----
    `MaskedIterator` is not exported by the `ma` module. Instead of
    instantiating a `MaskedIterator` directly, use `MaskedArray.flat`.

    Examples
    --------
    >>> x = np.ma.array(arange(6).reshape(2, 3))
    >>> fl = x.flat
    >>> type(fl)
    <class 'numpy.ma.core.MaskedIterator'>
    >>> for item in fl:
    ...     print(item)
    ...
    0
    1
    2
    3
    4
    5

    Extracting more than a single element b indexing the `MaskedIterator`
    returns a masked array:

    >>> fl[2:4]
    masked_array(data = [2 3],
                 mask = False,
           fill_value = 999999)

    c��||_|jj|_|jt
ur	d|_dS|jj|_dSr)r�rj�flat�dataiterrqr��maskiter)r}r�s  r�r~zMaskedIterator.__init__M
s;�������
��
�
�8�v��� �D�M�M�M��H�M�D�M�M�Mr�c��|Srr�r�s r�rzMaskedIterator.__iter__V
����r�c��|j�|���t|j����}|j��|j�|��}t
|t��r|j|_||_	n?t
|tj��rt|||jj
���S|rtS|S)N�ro�hardmask)r��__getitem__rlr^r�r�r!rr�rqrrHr��	_hardmaskrw)r}�indxrUrqs    r�r�zMaskedIterator.__getitem__Y
s�����*�*�4�0�0�5�5�d�4�7�m�m�D�D���=�$��M�-�-�d�3�3�E��%��)�)�
�$�l���$�����E�2�7�+�+�
��V�%�$�'�:K�L�L�L�L��
��
��
r�c�t�t|��|j|<|j�t|��|j|<dSdSr)rXr�r�rZ)r}�indexr-s   r��__setitem__zMaskedIterator.__setitem__h
s>��&�u�~�~��
�e���=�$�#/��#6�#6�D�M�%� � � �%�$r�c���t|j��}|j�St|j��}t|tj��rt
|||jj���S|rtS|S)aT
        Return the next value, or raise StopIteration.

        Examples
        --------
        >>> x = np.ma.array([3, 2], mask=[0, 1])
        >>> fl = x.flat
        >>> next(fl)
        3
        >>> next(fl)
        masked
        >>> next(fl)
        Traceback (most recent call last):
          ...
        StopIteration

        Nr�)
�nextr�r�r!rrHr�r�r�rw)r}r�r�s   r��__next__zMaskedIterator.__next__m
sj��$
�������=�$��T�]�#�#�A��!�R�W�%�%�
��Q�Q���1B�C�C�C�C��
��
��r�N)	r�r�r�r�r~rr�r�r�r�r�r�rr
sj������-�-�^*�*�*�������7�7�7�
����r�rc���eZdZdZdZeZdZeZ	dZ
dZdedddddddddfd	�Zd
�Z
d�Zd�d�Zd�d
�Zd�Zejdd���d���Ze�fd���Zej�fd���Ze�fd���Zej�fd���Zd�d�ZeZed���Zejd���Zed���Zejd���Zd�Zd�Zed���Zd�Z ed���Z!d �Z"ed!���Z#d"�Z$ee$�#��Z%ee$�#��Z&ed$���Z'e'jd%���Z'ed&���Z(e(jd�d'���Z(e(j)Z*e(j+Z,d�d(�Z-d)�Z.d�d*�Z/d+�Z0d,�Z1d-�Z2d.�Z3d/�Z4d0�Z5d1�Z6d2�Z7d3�Z8d4�Z9d5�Z:d6�Z;d7�Z<d8�Z=d9�Z>d:�Z?d;�Z@d<�ZAd=�ZBd>�ZCd?�ZDd@�ZEdA�ZFdB�ZGdC�ZHdD�ZIdE�ZJdF�ZKdG�ZLdH�ZMdI�ZNdJ�ZOdK�ZPedL���ZQeQj)ZRedM���ZSeSj)ZTdejUfdN�ZVd�dP�ZWdQ�ZXd�dR�ZYd�dT�ZZdU�Z[dV�Z\ddejUfdW�Z]ddejUfdX�Z^dY�Z_d��fd[�	Z`ej`je`_d�d\�ZadddejUfd]�Zbd�d^�ZcdddejUfd_�ZdedZed�d`�ZfdddejUf�fda�	Zgd�db�ZhddddejUf�fdc�	Ziejijei_ddddejUfdd�Zjd�de�ZkejUddddfdf�Zld�ejUdg�dh�Zmd�ejUdg�di�Zn		d�dk�ZodddejUfdl�ZpdddejUfdm�Zqd�dn�Zr�fdo�Zs�fdp�Ztd�dq�Zuevdr��Zwevds��Zxevdt��Zyevdu��Zzevdv��Z{evdw��Z|edx��#��Z}evdy��Z~d�dz�Zd�d{�Z�d�d|�Z�d�d�Z�d��Z�e�Z��fd��Z��fd��Z�d��Z�d�d��Z��xZ�S)�raz
    An array class with possibly masked values.

    Masked values of True exclude the corresponding element from any
    computation.

    Construction::

      x = MaskedArray(data, mask=nomask, dtype=None, copy=False, subok=True,
                      ndmin=0, fill_value=None, keep_mask=True, hard_mask=None,
                      shrink=True, order=None)

    Parameters
    ----------
    data : array_like
        Input data.
    mask : sequence, optional
        Mask. Must be convertible to an array of booleans with the same
        shape as `data`. True indicates a masked (i.e. invalid) data.
    dtype : dtype, optional
        Data type of the output.
        If `dtype` is None, the type of the data argument (``data.dtype``)
        is used. If `dtype` is not None and different from ``data.dtype``,
        a copy is performed.
    copy : bool, optional
        Whether to copy the input data (True), or to use a reference instead.
        Default is False.
    subok : bool, optional
        Whether to return a subclass of `MaskedArray` if possible (True) or a
        plain `MaskedArray`. Default is True.
    ndmin : int, optional
        Minimum number of dimensions. Default is 0.
    fill_value : scalar, optional
        Value used to fill in the masked values when necessary.
        If None, a default based on the data-type is used.
    keep_mask : bool, optional
        Whether to combine `mask` with the mask of the input data, if any
        (True), or to use only `mask` for the output (False). Default is True.
    hard_mask : bool, optional
        Whether to use a hard mask or not. With a hard mask, masked values
        cannot be unmasked. Default is False.
    shrink : bool, optional
        Whether to force compression of an empty mask. Default is True.
    order : {'C', 'F', 'A'}, optional
        Specify the order of the array.  If order is 'C', then the array
        will be in C-contiguous order (last-index varies the fastest).
        If order is 'F', then the returned array will be in
        Fortran-contiguous order (first-index varies the fastest).
        If order is 'A' (default), then the returned array may be
        in any order (either C-, Fortran-contiguous, or even discontiguous),
        unless a copy is required, in which case it will be C-contiguous.

    Examples
    --------

    The ``mask`` can be initialized with an array of boolean values
    with the same shape as ``data``.

    >>> data = np.arange(6).reshape((2, 3))
    >>> np.ma.MaskedArray(data, mask=[[False, True, False],
    ...                               [False, False, True]])
    masked_array(
      data=[[0, --, 2],
            [3, 4, --]],
      mask=[[False,  True, False],
            [False, False,  True]],
      fill_value=999999)

    Alternatively, the ``mask`` can be initialized to homogeneous boolean
    array with the same shape as ``data`` by passing in a scalar
    boolean value:

    >>> np.ma.MaskedArray(data, mask=False)
    masked_array(
      data=[[0, 1, 2],
            [3, 4, 5]],
      mask=[[False, False, False],
            [False, False, False]],
      fill_value=999999)

    >>> np.ma.MaskedArray(data, mask=True)
    masked_array(
      data=[[--, --, --],
            [--, --, --]],
      mask=[[ True,  True,  True],
            [ True,  True,  True]],
      fill_value=999999,
      dtype=int64)

    .. note::
        The recommended practice for initializing ``mask`` with a scalar
        boolean value is to use ``True``/``False`` rather than
        ``np.True_``/``np.False_``. The reason is :attr:`nomask`
        is represented internally as ``np.False_``.

        >>> np.False_ is np.ma.nomask
        True

    �F�di�NTrc�L����tj||||d|����t|dt�����}t	|t
��r|j�jkrd}t	||��r:|r8t	|t��s#tj	�t|�����ntj	�|���t|d��r!t	|t��s|j�_t�j
���|tu�r'|s2|
rt�_�n�tj�j�����_�n�t	|t t"f��rq	tj�fd�|D������}n#t$t&f$r
t}YnwxYw�t(kr"|���r|�_d�_�n�|�_|rZ�j����_t1|��tur&|jj|jkr|j|j_�n�|�d}|dur'�t(krtj�j����}nv|dur'�t(krtj�j����}nK	tj||��	��}n2#t&$r%tj�fd
�|D������}YnwxYw|j�jkrh�j|j}}
|dkrtj|�j��}n7||
krtj|�j��}nd}t;||
|fz���d}�jtur|�_|�_n[|s|�_|�_nI�j
j��fd
����j|��ntj|�j���_d�_|�t|dd��}|�tA|�j
���_!|	�t|dd���_"n|	�_"|�_#�S)z�
        Create a new masked array from scratch.

        Notes
        -----
        A masked array can also be created by taking a .view(MaskedArray).

        T)rr=�orderri�ndmin�
_baseclassrqrc�`��g|]*}ttj|�j�������+S)r)rZrr/r)rr�rjs  �r�rz'MaskedArray.__new__.<locals>.<listcomp>*sB���(�(�(��&�b�m�A�U�[�&I�&I�&I�J�J�(�(�(r�FNrFc�P��g|]"}t|gt���z����#Sr��rr<�rr��mdtypes  �r�rz'MaskedArray.__new__.<locals>.<listcomp>S�.���$L�$L�$L�!�U�A�3��V���+<�%=�%=�$L�$L�$Lr�r�z?Mask and data not compatible: data size is %i, mask size is %i.c���|jjD]0}||||}}|jj�
�||���+||z}�1dS)z'do a|=b on each field of a, recursivelyNr)rSr�r�af�bf�
_recursive_ors     �r�r�z*MaskedArray.__new__.<locals>._recursive_orks[���()��
�-�-��,-�d�G�Q�t�W�R��#%�8�>�#=�$1�M�"�b�$9�$9�$9�$9�$&�"�H�B�B�-�-r��_fill_valuer�)$rrr�r^r!rr�r`rrlr"rqrtrr�r�rrurIr�rr!�_sharedmaskr=rYr�r�r�r�rrrqrPr�r�r�)rermrorr=rir�rM�	keep_mask�	hard_maskrr�r��nd�nm�msgrjr�r�s                @@@r��__new__zMaskedArray.__new__�
s���������U��$�D��?�?�?���T�<��e���=�=�
��d�K�(�(�	�d�j�E�K�.G�.G��D�
�d�C� � �	-�U�	-�:�d�N�3S�3S�	-��L���T�
�
�3�3�E�E��L���,�,�E��4��!�!�	%�*�T�7�*C�*C�	%��*�E�K�!���-�-���6�>�>��!
:��F�"(�E�K�K�#%�(�5�;�f�"E�"E�"E�E�K�K��D�5�$�-�0�0�
:�"��8�(�(�(�(�"&�(�(�(�/5�7�7�7�D�D��#�I�.�"�"�"�!�D�D�D�"�����h�&�&�D�H�H�J�J�&�"&�E�K�(-�E�%��(,�H��!��
:�"'�+�"2�"2�"4�"4�E�K��t�}�}�F�2�2� �:�+�t�z�9�9�/3�z�D�J�,���|����t�|�|��(� 2� 2��w�u�{�&�9�9�9�������6�X�#5�#5��x���6�:�:�:���2��8�D�t�6�B�B�B�D�D�� �2�2�2��8�$L�$L�$L�$L�t�$L�$L�$L�*0�2�2�2�D�D�D�2�����z�U�[�(�(�!�J��	�R����7�7��9�T�5�;�7�7�D�D��2�X�X��:�d�E�K�8�8�D�D�-�C�#�C�2�r�(�N�3�3�3����{�f�$�$�"���(,�H��!�!� �.�"&�E�K�,0��E�%�%��{�(�4�-�-�-�-�-�&�
�e�k�4�8�8�8�8�&(�m�D�%�+�&F�&F���(-�E�%��� ��}�d�;�;�J��!� 1�*�e�k� J� J�E����%�d�K��?�?�E�O�O�'�E�O�%����s$�""F�F �F �J+�+,K�Kc��t|t��rt|��}nt}i}|�t	|di����|�t	|di����t|t
��s$|�t	|di����t
t	|dd��t	|dd��t	|dd��t	|d	d��t	|d
|��||���}|j�|��|j�|��dS)z9
        Copies some attributes of obj to self.

        �_optinfo�	_basedict�__dict__r�Nr�Fr��_isfieldr�)r�r�r�r�r�r�r�)r!rr^�updater�rr[r�)r}r�r�r��_dicts     r�r�zMaskedArray._update_from�s0��
�c�7�#�#�	!��c���J�J� �J��������Z��4�4�5�5�5������[�"�5�5�6�6�6��#�{�+�+�	:��O�O�G�C��R�8�8�9�9�9����m�T�!B�!B�&�s�K��?�?�!(��m�U�!C�!C�%�c�:�u�=�=� '��\�:� F� F�&�'�
)�)�)��	
�
���U�#�#�#��
���X�&�&�&��r�c�\�|�|��t|t��r�|jj�t|��}nt
|��}|tur�|jdd|jddkrc|j|jkr|j}nt|j��}|j
jrd}n|j
jrd}nd}|�
||��}n|���}nt}||_|jturA	|j|j_n.#t"$rt|_Ynt$t&f$rYnwxYw|j�!t+|j|j��|_dS|jj�t+d|j��|_dSdS)z.
        Finalizes the masked array.

        Nrmr�C�F�K)r�r!rrrrZrYr��__array_interface__rt�flags�c_contiguous�f_contiguous�astyperlrqr�rIr�rkr�rP)r}r�rq�_mask_dtyper�s     r��__array_finalize__zMaskedArray.__array_finalize__�s���	
���#����8�c�7�#�#�'	��y��*�$�S�)�)���������V�#�#��(?��(G��(J��/��7��:�);�);��:���*�*�"'�+�K�K�"1�$�*�"=�"=�K��:�*� ��E�E��Z�,� ��E�E��E����[�%�8�8����
�
������E���
��:�V�#�#�
�#'�:��
� � ���
$�
$�
$�#��
�
�
��~�.�
�
�
���
����
��'�0��1A�4�:�N�N�D����
�Z�
�
)�0��t�z�B�B�D����*�
)s�D.�.E�E�Ec�4�||ur|}n7|�t|����}|�|��|��V|j���|_|\}}}|d|j�}t
td�|D����}t�	|d��}	|	��tjdd���5t|	|�d��}
ddd��n#1swxYwY|
�
��rl	t|d}n/#t$rt|}Ynt $r
|j}YnwxYwtj|||
���|t&ur|
}n||
z}||ur|jdkr	|rt*S||_d	|_|S)
zr
        Special hook for ufuncs.

        Wraps the numpy array and sets the mask according to context.

        Nc�,�g|]}t|����Sr��rZ)r�args  r�rz.MaskedArray.__array_wrap__.<locals>.<listcomp>s �� I� I� I�s��c�!2�!2� I� I� Ir�r�r�Tr�r�r�F)rlr^r�rqr=�ninrrvr�r*rr�rNr!r�r�r1rMr�r�r�rwr�)r}r��contextrU�funcr��out_i�
input_argsr�r�r�rMs            r��__array_wrap__zMaskedArray.__array_wrap__�s	���$�;�;��F�F��X�X�d�4�j�j�)�)�F�����%�%�%���!�<�,�,�.�.�F�L� '��D�$���i�t�x�i��J��w� I� I�j� I� I� I�J�J�A�!�%�%�d�D�1�1�F��!��[��(�C�C�C�:�:��v�v�z�2�D�9�9�A�:�:�:�:�:�:�:�:�:�:�:����:�:�:�:��5�5�7�7�$�5�%0��%6�r�%:�
�
��$�7�7�7�%0��%6�
�
�
�#�5�5�5�%)�_�
�
�
�5�����I�f�j��:�:�:�:��F�{�{������U���T�!�!�f�l�b�&8�&8�Q�&8��
� ���%*��"��
s*�C'�'C+�.C+�D�E�4E�Ec��|�-|�tj|��}n�tj||��}n�|�i	t|t��rtj||��}d}ntj||��}n;#t$rtj||��}YnwxYwtj|||��}t	|��t
ur|j���|_t|dd���|�|�nd|_n||_	|S)a3

        Return a view of the MaskedArray data.

        Parameters
        ----------
        dtype : data-type or ndarray sub-class, optional
            Data-type descriptor of the returned view, e.g., float32 or int16.
            The default, None, results in the view having the same data-type
            as `a`. As with ``ndarray.view``, dtype can also be specified as
            an ndarray sub-class, which then specifies the type of the
            returned object (this is equivalent to setting the ``type``
            parameter).
        type : Python type, optional
            Type of the returned view, either ndarray or a subclass.  The
            default None results in type preservation.
        fill_value : scalar, optional
            The value to use for invalid entries (None by default).
            If None, then this argument is inferred from the passed `dtype`, or
            in its absence the original array, as discussed in the notes below.

        See Also
        --------
        numpy.ndarray.view : Equivalent method on ndarray object.

        Notes
        -----

        ``a.view()`` is used two different ways:

        ``a.view(some_dtype)`` or ``a.view(dtype=some_dtype)`` constructs a view
        of the array's memory with a different data-type.  This can cause a
        reinterpretation of the bytes of memory.

        ``a.view(ndarray_subclass)`` or ``a.view(type=ndarray_subclass)`` just
        returns an instance of `ndarray_subclass` that looks at the same array
        (same shape, dtype, etc.)  This does not cause a reinterpretation of the
        memory.

        If `fill_value` is not specified, but `dtype` is specified (and is not
        an ndarray sub-class), the `fill_value` of the MaskedArray will be
        reset. If neither `fill_value` nor `dtype` are specified (or if
        `dtype` is an ndarray sub-class), then the fill value is preserved.
        Finally, if `fill_value` is specified, but `dtype` is not, the fill
        value is set to the specified value.

        For ``a.view(some_dtype)``, if ``some_dtype`` has a different number of
        bytes per entry than the previous dtype (for example, converting a
        regular array to a structured array), then the behavior of the view
        cannot be predicted just from the superficial appearance of ``a`` (shown
        by ``print(a)``). It also depends on exactly how ``a`` is stored in
        memory. Therefore if ``a`` is C-ordered versus fortran-ordered, versus
        defined as a slice or transpose, etc., the view may give different
        results.
        Nr�)
rrlrar�rYr�rqr�r�rM)r}rr^rMr3s     r�rlzMaskedArray.view7s ��p�=��|� ��d�+�+��� ��d�D�1�1���
�\�
3��e�W�-�-�7�$�\�$��6�6�F� �E�E�$�\�$��6�6�F����
3�
3�
3� ��d�E�2�2����
3�����\�$��t�4�4�F�
�6�?�?�&�(�(�!�<�,�,�.�.�F�L��6�=�$�/�/�;��!��=��)-�F�&�&�$.��!��
s�AA6�6B�Bc��|j|}|j}d�}d�}|tur||}||��}n8t}||j|��}|�|t|��|��}|r�t	|t
j��rt|||j���S|j	j
t
jur8t	|t
j��r|tur|rt|d���S|S|rtS|S|�t|����}|�|��t#|��r�|j��|j||_t	|jt
j��st'd���|jjdkr�|j|jjdk���s(t/jd	|�d
|jd�d�d�
��|jjdd��d���|_d|_|tur!t7||j��|_d|_|S)zi
        x.__getitem__(y) <==> x[y]

        Return the item described by i, as a masked array.

        c�8�t|tj��Sr)r!rrr�s r��
_is_scalarz+MaskedArray.__getitem__.<locals>._is_scalar�s��!�!�R�Z�0�0�0�0r�c���t|tj��sdS|jjtjur|j|jurdSn$t	|��jtjkrdSdS)z�
            Return whether `elem` is a scalar result of indexing `arr`, or None
            if undecidable without promoting nomask to a full mask
            TFN)r!rrrr^�object_r�)r��elems  r��_scalar_heuristicz2MaskedArray.__getitem__.<locals>._scalar_heuristic�sn���d�B�J�/�/�

��t����2�:�-�-��9�D�J�.�.� �4�/��c���&�'�*=�=�=��u��4r�Nr�T�rozInternal NumPy error.rz&Upon accessing multidimensional field zi, need to keep dimensionality of fill_value at 0. Discarding heterogeneous fill_value and setting all to r0�r�r��r�)rmrqr�rZr!rrHr�r�rr^r�rrwrrlr�rxr��RuntimeErrorr�r�rr�r�r�r�r�r�r�)r}r��doutrqr�r��mout�scalar_expecteds        r�r�zMaskedArray.__getitem__�s����y�����
��	1�	1�	1�	�	�	�.������;�D�(�j��.�.�O�O��D�/�/��	�4�@�@�O��&�#-�*�\�$�-?�-?��-E�"F�"F���A	(��$���(�(�
 ��T��t�~�F�F�F�F��*�/�R�Z�/�/��T�2�:�.�.�0��f�$�$�� �&�t�$�7�7�7�7��K�� �!�M��K��9�9�T�$�Z�Z�(�(�D����d�#�#�#�+�D�1�1�
%��#�/�'+�'7��'=�D�$�&�d�&6��
�C�C�D�*�+B�C�C�C��'�,�q�0�0� $� 0� $� 0� 5�a� 8�!9�:=�#�%�%�.�$�M�!C�#'�!C�!C�+/�*:�1�*=�	!C�!C�!C�
,-�
.�.�.�.�,0�+;�+@��1��+E�+M�+M�ST�+M�+U�+U��(� $��
��6�!�!�$�T�4�:�6�6��
�#'�� ��r�r�)�overrrc���|turtd���|j}|j}t	|t
��rC|||<|tur!t|j|j	��x|_}t|��||<dS|j	}|tur\|turt|j|��x}|_|j�)tdgt|j��z��||<nd||<dSt|d|��}t|��}|j�.|tur%tdgt|j��z��}|tur0|||<|tur!t|j|��x}|_|||<n�|js@t	|t ��r t	|t ��s|||j<n�|||<|||<n�t%|d��r-|j	t&kr|t)j|��z}|||<nv|j�d}t-|���t/|||d���}	|j|}
|
jd	krt3j|
||	�
��n|	tur|}
|
||<|	||<dS)z�
        x.__setitem__(i, y) <==> x[i]=y

        Set item described by index. If value is masked, masks those
        locations.

        z Cannot alter the masked element.NTrjFrz,Flexible 'hard' masks are not yet supported.r�r�r�)rwrrjrqr!r+r�rur�rrYrrr<r�r�rxrmr"rr�rp�NotImplementedErrorrvr�rr�)r}r�r-rjrq�_dtype�dval�mvalrO�mindx�dindxs           r�r�zMaskedArray.__setitem__
s����6�>�>��>�?�?�?��
���
���d�C� � �	��E�$�K�����%3�D�J��
�%K�%K�K��
�U�!�%�.�.�E�$�K��F�����F�?�?�����%3�D�J��%G�%G�G���
��|�'�#�T�F�S���->�->�$>�?�?��d���"��d���F��u�g�u�-�-���u�~�~���<�#������%��3�v�|�#4�#4�4�5�5�D��F�?�?��E�$�K��6�!�!�%3�D�J��%G�%G�G���
�"��d�����	 ��4��.�.�
#�"�5�,�7�7�
#�#'��d�i� � �"��d��"��d���
�T�7�
#�
#�	 ���x�)?�)?��%�+�E�2�2�2�D��E�$�K�K��|�'�H��)�'�2�2�2��E�$�K��D�9�9�9�E��J�t�$�E��z�A�~�~��	�%��e�V�4�4�4�4�4��&������E�$�K��E�$�K��r�c�*��t��jSr)r�r�r}r�s �r�rzMaskedArray.dtypeY
�����w�w�}�r�c�V��ttt|����j�||��|jtur^|j�t|��t��|_	|j
|j_
dS#ttf$rYdSwxYwdSr)
r�rr^r�__set__rqr�rlrtrr�rkr�)r}rr�s  �r�rzMaskedArray.dtype]
s����
�k�4��:�:�&�&�,�4�4�T�5�A�A�A��:�V�#�#�������)?�)?��I�I�D�J�
�#'�:��
� � � ��"�I�.�
�
�
����
����
$�#s�>B�B&�%B&c�*��t��jSr)r�r�r�s �r�r�zMaskedArray.shapei
r�r�c����ttt|����j�||��t|��tur|j|j_dSdSr)r�rr^r�r�rYr�rq)r}r�r�s  �r�r�zMaskedArray.shapem
sY���
�k�4��:�:�&�&�,�4�4�T�5�A�A�A��4�=�=��&�&�#�z�D�J����'�&r�c����|j}|j}|turd}|tur'|turdSt	|j|��x}|_|j�P|jr||z}�n�t|tttjtj
f��r||d<�nL||_�nC|j�tj|d���}|jsm|jjdkrGtjt%|���gt)���z������}na|����}nK	tj||����}n2#t,$r%tj�fd	�|D������}YnwxYw|jr!|jD]}||xx||zcc<�n?t|tttjtj
f��r||d<n||_|jr|j|_dS)
z 
        Set the mask.

        TN.Fr�r�rrFc�P��g|]"}t|gt���z����#Sr�r�r�s  �r�rz+MaskedArray.__setmask__.<locals>.<listcomp>�
r�r�)rrqrwr�rur�rr�r!�intr�rr	�numberr�rr�r(rr?r<r�r�)r}ror=�idtype�current_mask�nr�s      @r�rwzMaskedArray.__setmask__u
s1���
����z���6�>�>��D��6�!�!��v�~�~���(6�t�z�6�(J�(J�J�L�4�:��<���~�	
)���$����D�3��r�x���"C�D�D�
)�$(��S�!�!�%)��!�!�"�'�F��8�D�u�-�-�-�D��9�
2��:�?�c�)�)��8�E�4�9�9�;�;�-�#�f�+�+�*E�$F�$F�*0�2�2�2�D�D� �;�;�v�.�.�D�D�2��8�D�t�6�B�B�B�D�D�� �2�2�2��8�$L�$L�$L�$L�t�$L�$L�$L�*0�2�2�2�D�D�D�2�����~�

)���/�/�A� ��O�O�O�t�A�w�.�O�O�O�O�/�
�D�3��r�x���"C�D�D�
)�$(��S�!�!�%)��!���	,�!%��L���s�4E�,E;�:E;c�4�|j���S)z Current mask. )rqrlr�s r�rozMaskedArray.mask�
s���z��� � � r�c�0�|�|��dSr)rw)r}r-s  r�rozMaskedArray.mask�
s����������r�c��|j�t��}|jj�|Stjt|��d���S)a�
        Get or set the mask of the array if it has no named fields. For
        structured arrays, returns a ndarray of booleans where entries are
        ``True`` if **all** the fields are masked, ``False`` otherwise:

        >>> x = np.ma.array([(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)],
        ...         mask=[(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)],
        ...        dtype=[('a', int), ('b', int)])
        >>> x.recordmask
        array([False, False,  True, False, False])
        Nr�r�)rqrlrrrrrrQ)r}rqs  r��
recordmaskzMaskedArray.recordmask�
sE���
����(�(���;��$��L��v�.�u�5�5�B�?�?�?�?r�c� �td���)Nz*Coming soon: setting the mask per records!�r�)r}ros  r�r�zMaskedArray.recordmask�
s��!�"N�O�O�Or�c��d|_|S)a�
        Force the mask to hard, preventing unmasking by assignment.

        Whether the mask of a masked array is hard or soft is determined by
        its `~ma.MaskedArray.hardmask` property. `harden_mask` sets
        `~ma.MaskedArray.hardmask` to ``True`` (and returns the modified
        self).

        See Also
        --------
        ma.MaskedArray.hardmask
        ma.MaskedArray.soften_mask

        T�r�r�s r�r]zMaskedArray.harden_mask�
s������r�c��d|_|S)a�
        Force the mask to soft (default), allowing unmasking by assignment.

        Whether the mask of a masked array is hard or soft is determined by
        its `~ma.MaskedArray.hardmask` property. `soften_mask` sets
        `~ma.MaskedArray.hardmask` to ``False`` (and returns the modified
        self).

        See Also
        --------
        ma.MaskedArray.hardmask
        ma.MaskedArray.harden_mask

        Fr�r�s r�r�zMaskedArray.soften_mask�
s������r�c��|jS)a�
        Specifies whether values can be unmasked through assignments.

        By default, assigning definite values to masked array entries will
        unmask them.  When `hardmask` is ``True``, the mask will not change
        through assignments.

        See Also
        --------
        ma.MaskedArray.harden_mask
        ma.MaskedArray.soften_mask

        Examples
        --------
        >>> x = np.arange(10)
        >>> m = np.ma.masked_array(x, x>5)
        >>> assert not m.hardmask

        Since `m` has a soft mask, assigning an element value unmasks that
        element:

        >>> m[8] = 42
        >>> m
        masked_array(data=[0, 1, 2, 3, 4, 5, --, --, 42, --],
                     mask=[False, False, False, False, False, False,
                           True, True, False, True],
               fill_value=999999)

        After hardening, the mask is not affected by assignments:

        >>> hardened = np.ma.harden_mask(m)
        >>> assert m.hardmask and hardened is m
        >>> m[:] = 23
        >>> m
        masked_array(data=[23, 23, 23, 23, 23, 23, --, --, 23, --],
                     mask=[False, False, False, False, False, False,
                           True, True, False, True],
               fill_value=999999)

        r�r�s r�r�zMaskedArray.hardmasks
��T�~�r�c�^�|jr%|j���|_d|_|S)aY
        Copy the mask and set the `sharedmask` flag to ``False``.

        Whether the mask is shared between masked arrays can be seen from
        the `sharedmask` property. `unshare_mask` ensures the mask is not
        shared. A copy of the mask is only made if it was shared.

        See Also
        --------
        sharedmask

        F)r�rqr=r�s r��unshare_maskzMaskedArray.unshare_mask1s/����	%�����*�*�D�J�$�D���r�c��|jS)z' Share status of the mask (read-only). )r�r�s r��
sharedmaskzMaskedArray.sharedmaskCs
����r�c�8�t|j��|_|S)a
        Reduce a mask to nomask when possible.

        Parameters
        ----------
        None

        Returns
        -------
        None

        Examples
        --------
        >>> x = np.ma.array([[1,2 ], [3, 4]], mask=[0]*4)
        >>> x.mask
        array([[False, False],
               [False, False]])
        >>> x.shrink_mask()
        masked_array(
          data=[[1, 2],
                [3, 4]],
          mask=False,
          fill_value=999999)
        >>> x.mask
        False

        )r�rqr�s r�rEzMaskedArray.shrink_maskHs��8"�$�*�-�-��
��r�c��|jS)z+ Class of the underlying data (read-only). )r�r�s r��	baseclasszMaskedArray.baseclassgs����r�c�6�tj||j��S)a�
        Returns the underlying data, as a view of the masked array.

        If the underlying data is a subclass of :class:`numpy.ndarray`, it is
        returned as such.

        >>> x = np.ma.array(np.matrix([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]])
        >>> x.data
        matrix([[1, 2],
                [3, 4]])

        The type of the data can be accessed through the :attr:`baseclass`
        attribute.
        )rrlr�r�s r��	_get_datazMaskedArray._get_datals���|�D�$�/�2�2�2r�)�fgetc� �t|��S)zF Return a flat iterator, or set a flattened version of self to value. )rr�s r�r�zMaskedArray.flat�s���d�#�#�#r�c�<�|���}||dd�<dSr)r�)r}r-�ys   r�r�zMaskedArray.flat�s ���J�J�L�L����!�!�!���r�c��|j�td|j��|_t|jt��r
|jdS|jS)a�
        The filling value of the masked array is a scalar. When setting, None
        will set to a default based on the data type.

        Examples
        --------
        >>> for dt in [np.int32, np.int64, np.float64, np.complex128]:
        ...     np.ma.array([0, 1], dtype=dt).get_fill_value()
        ...
        999999
        999999
        1e+20
        (1e+20+0j)

        >>> x = np.ma.array([0, 1.], fill_value=-np.inf)
        >>> x.fill_value
        -inf
        >>> x.fill_value = np.pi
        >>> x.fill_value
        3.1415926535897931 # may vary

        Reset to default:

        >>> x.fill_value = None
        >>> x.fill_value
        1e+20

        Nr�)r�rPrr!rr�s r�rMzMaskedArray.fill_value�sO��<��#�0��t�z�B�B�D���d�&��0�0�	(��#�B�'�'���r�c��t||j��}|jdkstjdt
d���|j}|�	||_dS||d<dS)Nrz�Non-scalar arrays for the fill value are deprecated. Use arrays with scalar values instead. The filled function still supports any array as `fill_value`.r�r�r�)rPrr�r�r��DeprecationWarningr�)r}r-r�r�s    r�rMzMaskedArray.fill_value�sr��"�5�$�*�5�5���{�a����M�<�#�q�	
2�
2�
2�
2��&����%�D����%�K��O�O�Or�c��|j}|tur|jS|�|j}nt	||j��}|turtj|��S|jj	�1|j�
d��}t||j|��n�|���s|jS|j�
d��}	tj
|||���n�#ttf$rJt!|t"���}|�t"��}tj|||f��}YnAt($r5|jjr�|rtj||j���}n|j}YnwxYw|S)a�
        Return a copy of self, with masked values filled with a given value.
        **However**, if there are no masked values to fill, self will be
        returned instead as an ndarray.

        Parameters
        ----------
        fill_value : array_like, optional
            The value to use for invalid entries. Can be scalar or non-scalar.
            If non-scalar, the resulting ndarray must be broadcastable over
            input array. Default is None, in which case, the `fill_value`
            attribute of the array is used instead.

        Returns
        -------
        filled_array : ndarray
            A copy of ``self`` with invalid entries replaced by *fill_value*
            (be it the function argument or the attribute of ``self``), or
            ``self`` itself as an ndarray if there are no invalid entries to
            be replaced.

        Notes
        -----
        The result is **not** a MaskedArray!

        Examples
        --------
        >>> x = np.ma.array([1,2,3,4,5], mask=[0,0,1,0,1], fill_value=-999)
        >>> x.filled()
        array([   1,    2, -999,    4, -999])
        >>> x.filled(fill_value=1000)
        array([   1,    2, 1000,    4, 1000])
        >>> type(x.filled())
        <class 'numpy.ndarray'>

        Subclassing is preserved. This means that if, e.g., the data part of
        the masked array is a recarray, `filled` returns a recarray:

        >>> x = np.array([(-1, 2), (-3, 4)], dtype='i8,i8').view(np.recarray)
        >>> m = np.ma.array(x, mask=[(True, False), (False, True)])
        >>> m.filled()
        rec.array([(999999,      2), (    -3, 999999)],
                  dtype=[('f0', '<i8'), ('f1', '<i8')])
        Nr�r�r)rqr�rjrMrPrr�rr/rr=rfr!r�r�rk�narrayrJr�r5r&r�r)r}rMr�rUr�s     r�rNzMaskedArray.filled�s���Z
�J����;�;��:������J�J�*�:�t�z�B�B�J��#�#�#��=��,�,�,��7�=�$��Z�_�_�S�)�)�F��f�d�j�*�=�=�=�=������	(��:���Z�_�_�S�)�)�F�

(��	�&�*�A�6�6�6�6�6���~�.�
7�
7�
7�#�J�f�=�=�=�
��M�M�&�)�)����1�q�*�o�6�6�����
(�
(�
(��:�#�(���(��X�j��
�C�C�C�F�F�!�Z�F���
(�����
s�C�AE7�9;E7�6E7c���tj|j��}|jtur>|�t
jtj|j������}|S)a�
        Return all the non-masked data as a 1-D array.

        Returns
        -------
        data : ndarray
            A new `ndarray` holding the non-masked data is returned.

        Notes
        -----
        The result is **not** a MaskedArray!

        Examples
        --------
        >>> x = np.ma.array(np.arange(5), mask=[0]*2 + [1]*3)
        >>> x.compressed()
        array([0, 1])
        >>> type(x.compressed())
        <class 'numpy.ndarray'>

        )rr�rjrqr�r8rrp)r}rms  r�r9zMaskedArray.compressedsN��,�}�T�Z�(�(���:�V�#�#��=�=����
�d�j�0I�0I�!J�!J�K�K�D��r�c�.�|j|j}}tj|��}|�|||����t
|����}|�|��|tur|�||���|_|S)a+
        Return `a` where condition is ``True``.

        If condition is a `~ma.MaskedArray`, missing values are considered
        as ``False``.

        Parameters
        ----------
        condition : var
            Boolean 1-d array selecting which entries to return. If len(condition)
            is less than the size of a along the axis, then output is truncated
            to length of condition array.
        axis : {None, int}, optional
            Axis along which the operation must be performed.
        out : {None, ndarray}, optional
            Alternative output array in which to place the result. It must have
            the same shape as the expected output but the type will be cast if
            necessary.

        Returns
        -------
        result : MaskedArray
            A :class:`~ma.MaskedArray` object.

        Notes
        -----
        Please note the difference with :meth:`compressed` !
        The output of :meth:`compress` has a mask, the output of
        :meth:`compressed` does not.

        Examples
        --------
        >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
        >>> x
        masked_array(
          data=[[1, --, 3],
                [--, 5, --],
                [7, --, 9]],
          mask=[[False,  True, False],
                [ True, False,  True],
                [False,  True, False]],
          fill_value=999999)
        >>> x.compress([1, 0, 1])
        masked_array(data=[1, 3],
                     mask=[False, False],
               fill_value=999999)

        >>> x.compress([1, 0, 1], axis=1)
        masked_array(
          data=[[1, 3],
                [--, --],
                [7, 9]],
          mask=[[False, False],
                [ True,  True],
                [False, False]],
          fill_value=999999)

        �r�rtr�)	rjrqrr0r8rlr^r�r�)r}r'r�rtrjrq�_news       r�r8zMaskedArray.compress5s���x�*�d�j����J�y�)�)�	��~�~�i�d��~�<�<�A�A�$�t�*�*�M�M�����$�����������	���=�=�D�J��r�c��t����r#|j}|tur	|j}�n$|j}|jdkr|jn|j}t|j��D]�}|j	||kr�|dz}tj|||f|���}tj|d|df|���}tj|||f|���}tj|d|df|���}��t|jd��}|�|��}t!||t��n|�|j��}|S)zq
        Replace masked values with masked_print_option, casting all innermost
        dtypes to object.
        r�r�r�rr�)r�rWrqr�rjr��_print_width�_print_width_1d�ranger�rr�r:r�rr�r]rNrM)	r}rorIrm�print_widthr��indr��rdtypes	         r��_insert_masked_printz MaskedArray._insert_masked_print}s\��
�&�&�(�(�	/��:�D��v�~�~��j����z��59�I��M�M�t�0�0�$(�$8��!�$�)�,�,�K�K�D��z�$�'�+�5�5�)�Q�.�� �h�t�c�C�4�[�t�D�D�D��!�~�s�1�v�s�1�v�.>�T�J�J�J�� �h�t�c�C�4�[�t�D�D�D��!�~�s�1�v�s�1�v�.>�T�J�J�J���.�t�z�3�?�?���k�k�&�)�)��&�s�D�2E�F�F�F�F��+�+�d�o�.�.�C��
r�c�D�t|�����Sr)r+rr�s r�r�zMaskedArray.__str__�s���4�,�,�.�.�/�/�/r�c
���
���|jtjurd}n|jj}tjj���dkr�|jdk}t|dt|��zt|��t|j��t|j��t|j
�����}t|j
j��}d�|rdnd|rd	nd
��}t"||zSd|�d�}tjj�|j
��p#tj|j��p
|jd
k}gd�}|r|�d��t/jd�|jdd�D����}	d�|	r`i�
|�
|d
<|dd�D]E}
t/j�t||d
z��t|
��z
��}d|z�
|
<�Fd}n�fd�|D���
|dz}i�tj|���d�
ddzd����d<tj|jd�
ddzd����d<t9|j���d<|r,tjj�|j
���d<d��
�fd �|D����}||zd!zS)"z1
        Literal string representation.

        r�qr�� )r�nlenrmror�rz{}_{}r�short�flxr��masked_�(r)rmrorMrc3�"K�|]
}|dkV��dS)r�Nr�)r�dims  r�rz'MaskedArray.__repr__.<locals>.<genexpr>�s&����!F�!F�s�#��(�!F�!F�!F�!F�!F�!Fr�Nr�r�r�c���i|]}|d�z��	S)rr�)rr�
min_indents  �r��
<dictcomp>z(MaskedArray.__repr__.<locals>.<dictcomp>�s ���9�9�9�q�q�#�
�*�9�9�9r��
z, rmzdata=�,)�	separator�prefix�suffixrozmask=rMz,
c3�^�K�|]'}d��||�|��V��(dS)z{}{}={}N)�format)rr�indents�reprss  ��r�rz'MaskedArray.__repr__.<locals>.<genexpr>�sQ�����
�
��
���W�Q�Z��E�!�H�5�5�
�
�
�
�
�
r�r%)r�rrr��core�
arrayprint�_get_legacy_print_moder�r[r<r+rqrMrrrr(�_legacy_print_templates�dtype_is_impliedrror�r"rvr�r��array2stringr�repr�dtype_short_reprr�)r}r�is_long�
parameters�
is_structured�keyr%�dtype_needed�keys�
is_one_rowrr�rUr)r r*s             @@@r�r[zMaskedArray.__repr__�s;�����
�?�b�j�(�(��D�D��?�+�D��7��4�4�6�6�#�=�=��i�!�m�G����3�t�9�9�_���Y�Y����_�_����)�)��$�*�o�o�
���J�!���!1�2�2�M��.�.�!�.���w�&�1���E���C�+�3�/�*�<�<�"�4�"�"�"����"�3�3�D�J�?�?�?�
��F�4�9���
��I��N�	�.�-�-���	!��K�K�� � � ��\�!F�!F�d�j��"��o�!F�!F�!F�F�F�
��
��	#��G�%�G�D��G���!�"�"�X�
%�
%���L��S��$�q�'�1A�-B�-B�S��V�V�-K�L�L�� �1�W���
�
��F�F�:�9�9�9�D�9�9�9�G��d�]�F������%�%�'�'���6�?�W�,��	����f�
�
���J���6�?�W�,��	����f�
�
#�4�?�3�3��l���	M��W�/�@�@���L�L�E�'�N����
�
�
�
�
��
�
�
�
�
������$�$r�c��t|t|����rdSt|dd��}|durt|dd��}|j|kS|duS)NF�__array_ufunc__�__array_priority__i���)r!r^r�r<)r}�other�array_ufunc�other_prioritys    r��_delegate_binopzMaskedArray._delegate_binop�sk���e�T�$�Z�Z�(�(�	��5��e�%6��>�>���%���$�U�,@�(�K�K�N��*�^�;�;��$�&�&r�c�^�t|��}|j}t||d���}t|��}|jj��|tjtjfvrtStj||��j}tj
||d���}||_|�|��}	|tjd|j��k}n|j}	||	|��}
t%|
tjt(f��r|rt*n|
S|t,urv|tjtjfvr\tj||||��|
��}
|j|
jkr,tj
||
j�����}|
�t5|����}
|
�|��||
_|
j�Y	t;|
jtj��}n1#t<t>f$rt;dtj��}YnwxYw||
_|
S)a�Compare self with other using operator.eq or operator.ne.

        When either of the elements is masked, the result is masked as well,
        but the underlying boolean data are still set, with self and other
        considered equal if both are masked, and unequal otherwise.

        For structured arrays, all fields are combined, with masked values
        ignored. The result is masked if all fields were masked, with self
        and other considered equal only if both were fully masked.
        Tr�N�rir�) rYrorvrXrr�operator�eq�ne�NotImplementedrr
r��broadcast_torqrNr�rmr!r	rrwr�r�r=rlr^r�r�rPr�rI)r}r=�compare�omask�smaskro�odata�broadcast_shape�
sbroadcast�sdata�checkr�s            r��_comparisonzMaskedArray._comparisons
��������	���u�e�$�/�/�/��������:��'��x�{�H�K�8�8�8�%�%�!�l�4��7�7�=�O�����d�K�K�K�J�#�J���%�%�e�,�,�E��B�G�B��
�3�3�3�D�D��I�E����u�%�%���e�b�h��-�.�.�	-�!�,�6�6�u�,��v���'�h�k�8�;�-G�"G�"G�
�H�T�7�7�5�%�#8�#8�%�@�@�E��z�U�[�(�(���t�U�[�9�9�>�>�@�@���
�
�4��:�:�&�&��
���4� � � ������(�
9�(��):�B�H�E�E�����z�*�
9�
9�
9�(��r�x�8�8����
9���� $�E���s�G5�5+H#�"H#c�B�|�|tj��S)a�Check whether other equals self elementwise.

        When either of the elements is masked, the result is masked as well,
        but the underlying boolean data are still set, with self and other
        considered equal if both are masked, and unequal otherwise.

        For structured arrays, all fields are combined, with masked values
        ignored. The result is masked if all fields were masked, with self
        and other considered equal only if both were fully masked.
        )rPrCrD�r}r=s  r��__eq__zMaskedArray.__eq__F�������x�{�3�3�3r�c�B�|�|tj��S)a�Check whether other does not equal self elementwise.

        When either of the elements is masked, the result is masked as well,
        but the underlying boolean data are still set, with self and other
        considered equal if both are masked, and unequal otherwise.

        For structured arrays, all fields are combined, with masked values
        ignored. The result is masked if all fields were masked, with self
        and other considered equal only if both were fully masked.
        )rPrCrErRs  r��__ne__zMaskedArray.__ne__SrTr�c�B�|�|tj��Sr)rPrC�lerRs  r��__le__zMaskedArray.__le__a�������x�{�3�3�3r�c�B�|�|tj��Sr)rPrC�ltrRs  r��__lt__zMaskedArray.__lt__drZr�c�B�|�|tj��Sr)rPrC�gerRs  r��__ge__zMaskedArray.__ge__grZr�c�B�|�|tj��Sr)rPrC�gtrRs  r��__gt__zMaskedArray.__gt__jrZr�c�Z�|�|��rtSt||��S)zD
        Add self to other, and return a new masked array.

        )r@rFrrRs  r��__add__zMaskedArray.__add__ms0��
����&�&�	"�!�!��4����r�c�"�t||��S)zD
        Add other to self, and return a new masked array.

        )rrRs  r��__radd__zMaskedArray.__radd__vs���5�$���r�c�Z�|�|��rtSt||��S)zK
        Subtract other from self, and return a new masked array.

        )r@rFr�rRs  r��__sub__zMaskedArray.__sub__s0��
����&�&�	"�!�!���e�$�$�$r�c�"�t||��S)zK
        Subtract self from other, and return a new masked array.

        )r�rRs  r��__rsub__zMaskedArray.__rsub__�s��
��t�$�$�$r�c�Z�|�|��rtSt||��S)z6Multiply self by other, and return a new masked array.)r@rFr�rRs  r��__mul__zMaskedArray.__mul__�s.������&�&�	"�!�!���e�$�$�$r�c�"�t||��S)zI
        Multiply other by self, and return a new masked array.

        )r�rRs  r��__rmul__zMaskedArray.__rmul__�s����t�$�$�$r�c�Z�|�|��rtSt||��S�zI
        Divide other into self, and return a new masked array.

        )r@rFrHrRs  r��__div__zMaskedArray.__div__�s0��
����&�&�	"�!�!��d�E�"�"�"r�c�Z�|�|��rtSt||��Srq)r@rFr�rRs  r��__truediv__zMaskedArray.__truediv__�s0��
����&�&�	"�!�!��4��'�'�'r�c�"�t||��S�zI
        Divide self into other, and return a new masked array.

        )r�rRs  r��__rtruediv__zMaskedArray.__rtruediv__�s��
�5�$�'�'�'r�c�Z�|�|��rtSt||��Srq)r@rFrSrRs  r��__floordiv__zMaskedArray.__floordiv__�s0��
����&�&�	"�!�!��D�%�(�(�(r�c�"�t||��Srv)rSrRs  r��
__rfloordiv__zMaskedArray.__rfloordiv__�s��
�E�4�(�(�(r�c�Z�|�|��rtSt||��S)zQ
        Raise self to the power other, masking the potential NaNs/Infs

        )r@rFr�rRs  r��__pow__zMaskedArray.__pow__�s0��
����&�&�	"�!�!��T�5�!�!�!r�c�"�t||��S)zQ
        Raise other to the power self, masking the potential NaNs/Infs

        )r�rRs  r��__rpow__zMaskedArray.__rpow__�s��
�U�D�!�!�!r�c���t|��}|jturM|turC|���r/t	|j|j��|_|xj|z
c_n|tur|xj|z
c_t|��}tj	|j|j�
d��|��}|j�|��|S)z.
        Add other to self in-place.

        r)
rYrqr�r!rur�rrXrr�r^rj�__iadd__�r}r=r��
other_datas    r�r�zMaskedArray.__iadd__�s���

�E�N�N���:��������1�5�5�7�7��+�D�J��
�C�C��
��
�
�a��
�
�������
�
�a��
�
��U�^�^�
��X�d�j�*�*:�*?�*?��*B�*B�J�O�O�
��
���J�'�'�'��r�c���t|��}|jturM|turC|���r/t	|j|j��|_|xj|z
c_n|tur|xj|z
c_t|��}tj	|j|j�
d��|��}|j�|��|S)z5
        Subtract other from self in-place.

        r)
rYrqr�r!rur�rrXrr�r^rj�__isub__r�s    r�r�zMaskedArray.__isub__����

�E�N�N���:��������1�5�5�7�7��+�D�J��
�C�C��
��
�
�a��
�
��
�f�_�_��J�J�!�O�J�J��U�^�^�
��X�d�j�*�*:�*?�*?��*B�*B�J�O�O�
��
���J�'�'�'��r�c���t|��}|jturM|turC|���r/t	|j|j��|_|xj|z
c_n|tur|xj|z
c_t|��}tj	|j|j�
d��|��}|j�|��|S)z3
        Multiply self by other in-place.

        r�)
rYrqr�r!rur�rrXrr�r^rj�__imul__r�s    r�r�zMaskedArray.__imul__�r�r�c�"�t|��}t���|j|��}t	|��}t||��}|���rHttj	\}}tj
||j�|��|��}|xj
|zc_
tj
|j
|j�d��|��}|j�|��|S)z1
        Divide self by other in-place.

        r�)rXr�r�rjrYrvr!r�rrHr�rr^rq�__idiv__�r}r=r��dom_mask�
other_mask�new_maskrrCs        r�r�zMaskedArray.__idiv__s���
�U�^�^�
�$�&�&�/�/��
�J�G�G���U�^�^�
��:�x�0�0���<�<�>�>�	G�#�B�I�.�I�Q�����j�.�3�3�D�9�9�:�G�G�J��
�
�h��
�
��X�d�j�*�*:�*?�*?��*B�*B�J�O�O�
��
���J�'�'�'��r�c�"�t|��}t���|j|��}t	|��}t||��}|���rHttj	\}}tj
||j�|��|��}|xj
|zc_
tj
|j
|j�d��|��}|j�|��|S)z7
        Floor divide self by other in-place.

        r�)rXr�r�rjrYrvr!r�rrSr�rr^rq�
__ifloordiv__r�s        r�r�zMaskedArray.__ifloordiv__s���
�U�^�^�
�$�&�&�/�/��
�J�G�G���U�^�^�
��:�x�0�0���<�<�>�>�	G�#�B�O�4�I�Q�����j�.�3�3�D�9�9�:�G�G�J��
�
�h��
�
��X�d�j�*�*:�*?�*?��*B�*B�J�O�O�
��
� � ��,�,�,��r�c�"�t|��}t���|j|��}t	|��}t||��}|���rHttj	\}}tj
||j�|��|��}|xj
|zc_
tj
|j
|j�d��|��}|j�|��|S)z6
        True divide self by other in-place.

        r�)rXr�r�rjrYrvr!r�rr�r�rr^rq�__itruediv__r�s        r�r�zMaskedArray.__itruediv__1s���
�U�^�^�
�$�&�&�/�/��
�J�G�G���U�^�^�
��:�x�0�0���<�<�>�>�	G�#�B�N�3�I�Q�����j�.�3�3�D�9�9�:�G�G�J��
�
�h��
�
��X�d�j�*�*:�*?�*?��*B�*B�J�O�O�
��
���
�+�+�+��r�c��t|��}tj|j|j�d��|��}t
|��}tjdd���5|j�	|��ddd��n#1swxYwYtj
tj|j����}|���rG|jtur|xj|zc_n||_tj|j|j|���t!||��}t!|j|��|_|S)z;
        Raise self to the power other, in place.

        r�r�r�Nr�)rXrr�rqrr^rYr�rj�__ipow__rprpr!r�r�rMrv)r}r=r�r�rrr�s      r�r�zMaskedArray.__ipow__DsT��
�U�^�^�
��X�d�j�*�*:�*?�*?��*B�*B�J�O�O�
��U�^�^�
�
�[��(�
;�
;�
;�	,�	,��J���
�+�+�+�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,����	,�	,�	,�	,��.���T�Z�!8�!8�9�9���;�;�=�=�	B��z��'�'��
�
�g�%�
�
�
�$��
��I�d�j�$�/��A�A�A�A��:�w�/�/���T�Z��2�2��
��s�(B�B�Bc���|jdkrtd���|jr"tjdd���t
jSt|�����S)z$
        Convert to float.

        r��7Only length-1 arrays can be converted to Python scalarsz,Warning: converting a masked element to nan.r�r�)	r�r�rqr�r�r�nanr�r?r�s r��	__float__zMaskedArray.__float__Ysd��
�9�q�=�=��0�1�1�
1�
�Z�	��M�H�UV�W�W�W�W��6�M��T�Y�Y�[�[�!�!�!r�c��|jdkrtd���|jrtd���t	|�����S)z"
        Convert to int.

        r�r�z.Cannot convert masked element to a Python int.)r�r�rqrr�r?r�s r��__int__zMaskedArray.__int__fsV��
�9�q�=�=��0�1�1�
1�
�Z�	N��L�M�M�M��4�9�9�;�;���r�c��|jj�t|����}|�|j��|S)a�
        The imaginary part of the masked array.

        This property is a view on the imaginary part of this `MaskedArray`.

        See Also
        --------
        real

        Examples
        --------
        >>> x = np.ma.array([1+1.j, -2j, 3.45+1.6j], mask=[False, True, False])
        >>> x.imag
        masked_array(data=[1.0, --, 1.6],
                     mask=[False,  True, False],
               fill_value=1e+20)

        )rj�imagrlr^rwrq�r}rUs  r�r�zMaskedArray.imagr�<��(���%�%�d�4�j�j�1�1�����4�:�&�&�&��
r�c��|jj�t|����}|�|j��|S)a�
        The real part of the masked array.

        This property is a view on the real part of this `MaskedArray`.

        See Also
        --------
        imag

        Examples
        --------
        >>> x = np.ma.array([1+1.j, -2j, 3.45+1.6j], mask=[False, True, False])
        >>> x.real
        masked_array(data=[1.0, --, 3.45],
                     mask=[False,  True, False],
               fill_value=1e+20)

        )rj�realrlr^rwrqr�s  r�r�zMaskedArray.real�r�r�c��	�|tjurind|i}|j}t|jtj��rU|tur%tj|jtj	���}|�
t|j����}|tu�r|jdkr!|dvrtj||j
����dS|�H|�dd��r+tj|jtj|j
�	��S|jSt%||j
���	d}�	D]}||j|z}�|�dd��rt'|j��}�	D]}d||<�n �	fd
�t)|j��D��}tj||tj���S|t,urdS|jd|tjd�|��S)
a
        Count the non-masked elements of the array along the given axis.

        Parameters
        ----------
        axis : None or int or tuple of ints, optional
            Axis or axes along which the count is performed.
            The default, None, performs the count over all
            the dimensions of the input array. `axis` may be negative, in
            which case it counts from the last to the first axis.

            .. versionadded:: 1.10.0

            If this is a tuple of ints, the count is performed on multiple
            axes, instead of a single axis or all the axes as before.
        keepdims : bool, optional
            If this is set to True, the axes which are reduced are left
            in the result as dimensions with size one. With this option,
            the result will broadcast correctly against the array.

        Returns
        -------
        result : ndarray or scalar
            An array with the same shape as the input array, with the specified
            axis removed. If the array is a 0-d array, or if `axis` is None, a
            scalar is returned.

        See Also
        --------
        ma.count_masked : Count masked elements in array or along a given axis.

        Examples
        --------
        >>> import numpy.ma as ma
        >>> a = ma.arange(6).reshape((2, 3))
        >>> a[1, :] = ma.masked
        >>> a
        masked_array(
          data=[[0, 1, 2],
                [--, --, --]],
          mask=[[False, False, False],
                [ True,  True,  True]],
          fill_value=999999)
        >>> a.count()
        3

        When the `axis` keyword is specified an array of appropriate size is
        returned.

        >>> a.count(axis=0)
        array([1, 1, 1])
        >>> a.count(axis=1)
        array([3, 0])

        r!rr��Nr)r�r�r�NF)rr�c�"��g|]\}}|�v�	|��Sr�r�)rr�r��axess   �r�rz%MaskedArray.count.<locals>.<listcomp>s-���.�.�.�$�!�Q� ��}�}��,�}�}r�r�r�r)rr
rqr!rm�matrixr�r�r�r	rlr^�	AxisErrorr�r*rr��intprru�	enumeraterrwr�)
r}r�r!r�r��items�ax�out_dimsrSr�s
         @r�rAzMaskedArray.count�s����p �2�;�.�.���Z��4J���J���d�i���+�+�	(��F�{�{��H�T�Z�r�x�8�8�8�����t�D�I���'�'�A���;�;��z�R����y�(�(��,�D�t�y�A�A�A�A��q����:�:�j�%�0�0�O��8�D�I�R�W�D�I�N�N�N�N��y� �'��d�i�8�8�D��E��
(�
(�����B��'����z�z�*�e�,�,�
.���
�+�+���$�$�A�"#�H�Q�K�K�$�.�.�.�.�)�D�J�*?�*?�.�.�.���7�8�U�"�'�:�:�:�:��6�>�>��1����x�;�T���;�;�F�;�;�;r�r�c�~�|dvr|jjjrdnd}tj|j|����t
|����}|�|��|jtur9tj|j|����
|j��|_nt|_|S)af
        Returns a 1D version of self, as a view.

        Parameters
        ----------
        order : {'C', 'F', 'A', 'K'}, optional
            The elements of `a` are read using this index order. 'C' means to
            index the elements in C-like order, with the last axis index
            changing fastest, back to the first axis index changing slowest.
            'F' means to index the elements in Fortran-like index order, with
            the first index changing fastest, and the last index changing
            slowest. Note that the 'C' and 'F' options take no account of the
            memory layout of the underlying array, and only refer to the order
            of axis indexing.  'A' means to read the elements in Fortran-like
            index order if `m` is Fortran *contiguous* in memory, C-like order
            otherwise.  'K' means to read the elements in the order they occur
            in memory, except for reversing the data when strides are negative.
            By default, 'C' index order is used.
            (Masked arrays currently use 'A' on the data when 'K' is passed.)

        Returns
        -------
        MaskedArray
            Output view is of shape ``(self.size,)`` (or
            ``(np.ma.product(self.shape),)``).

        Examples
        --------
        >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
        >>> x
        masked_array(
          data=[[1, --, 3],
                [--, 5, --],
                [7, --, 9]],
          mask=[[False,  True, False],
                [ True, False,  True],
                [False,  True, False]],
          fill_value=999999)
        >>> x.ravel()
        masked_array(data=[1, --, 3, --, 5, --, 7, --, 9],
                     mask=[False,  True, False,  True, False,  True, False,  True,
                           False],
               fill_value=999999)

        �kKaAr�r��r�)rjr��fncrr�rlr^r�rqr�r�r�)r}r��rs   r�r�zMaskedArray.ravels���f�F�?�?��:�+�/�8�C�C�S�E��M�$�*�E�2�2�2�7�7��T�
�
�C�C��	���t�����:�V�#�#��m�D�J�e�<�<�<�D�D�Q�W�M�M�A�G�G��A�G��r�c�,�|�|�dd�����|jj|i|���t|����}|�|��|j}|tur|j|i|��|_|S)a�
        Give a new shape to the array without changing its data.

        Returns a masked array containing the same data, but with a new shape.
        The result is a view on the original array; if this is not possible, a
        ValueError is raised.

        Parameters
        ----------
        shape : int or tuple of ints
            The new shape should be compatible with the original shape. If an
            integer is supplied, then the result will be a 1-D array of that
            length.
        order : {'C', 'F'}, optional
            Determines whether the array data should be viewed as in C
            (row-major) or FORTRAN (column-major) order.

        Returns
        -------
        reshaped_array : array
            A new view on the array.

        See Also
        --------
        reshape : Equivalent function in the masked array module.
        numpy.ndarray.reshape : Equivalent method on ndarray object.
        numpy.reshape : Equivalent function in the NumPy module.

        Notes
        -----
        The reshaping operation cannot guarantee that a copy will not be made,
        to modify the shape in place, use ``a.shape = s``

        Examples
        --------
        >>> x = np.ma.array([[1,2],[3,4]], mask=[1,0,0,1])
        >>> x
        masked_array(
          data=[[--, 2],
                [3, --]],
          mask=[[ True, False],
                [False,  True]],
          fill_value=999999)
        >>> x = x.reshape((4,1))
        >>> x
        masked_array(
          data=[[--],
                [2],
                [3],
                [--]],
          mask=[[ True],
                [False],
                [False],
                [ True]],
          fill_value=999999)

        r�r�r�)	r�r*rjr�rlr^r�rqr�)r}r�r�rUros     r�r�zMaskedArray.reshapeIs���t	�
�
�F�J�J�w��4�4�
�5�5�5�#���#�Q�1�&�1�1�6�6�t�D�z�z�B�B�����D�!�!�!��z���v���'�4�<��5�f�5�5�F�L��
r�c�$�d}t|���)av
        .. warning::

            This method does nothing, except raise a ValueError exception. A
            masked array does not own its data and therefore cannot safely be
            resized in place. Use the `numpy.ma.resize` function instead.

        This method is difficult to implement safely and may be deprecated in
        future releases of NumPy.

        zoA masked array does not own its data and therefore cannot be resized.
Use the numpy.ma.resize function instead.)rI)r}r�refcheckr��errmsgs     r�r�zMaskedArray.resize�s��=���� � � r��raisec�V�|jrj|jtur\|j|}t|d���}t|dd���}|�|j��||}||}|j�|||���|jturt|��turdSt|��}t|��tur|�|d|���n|�||j|���t|dd���}||_dS)aD
        Set storage-indexed locations to corresponding values.

        Sets self._data.flat[n] = values[n] for each n in indices.
        If `values` is shorter than `indices` then it will repeat.
        If `values` has some masked values, the initial mask is updated
        in consequence, else the corresponding values are unmasked.

        Parameters
        ----------
        indices : 1-D array_like
            Target indices, interpreted as integers.
        values : array_like
            Values to place in self._data copy at target indices.
        mode : {'raise', 'wrap', 'clip'}, optional
            Specifies how out-of-bounds indices will behave.
            'raise' : raise an error.
            'wrap' : wrap around.
            'clip' : clip to the range.

        Notes
        -----
        `values` can be a scalar or length 1 array.

        Examples
        --------
        >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
        >>> x
        masked_array(
          data=[[1, --, 3],
                [--, 5, --],
                [7, --, 9]],
          mask=[[False,  True, False],
                [ True, False,  True],
                [False,  True, False]],
          fill_value=999999)
        >>> x.put([0,4,8],[10,20,30])
        >>> x
        masked_array(
          data=[[10, --, 3],
                [--, 20, --],
                [7, --, 30]],
          mask=[[False,  True, False],
                [ True, False,  True],
                [False,  True, False]],
          fill_value=999999)

        >>> x.put(4,999)
        >>> x
        masked_array(
          data=[[10, --, 3],
                [--, 999, --],
                [7, --, 30]],
          mask=[[False,  True, False],
                [ True, False,  True],
                [False,  True, False]],
          fill_value=999999)

        Fr�Trh��modeNr)r�rqr�rr�r�rjr�rYrZrs)r}ra�valuesr�ror�s      r�r�zMaskedArray.put�s(��z�>�	#�d�j��6�6��:�g�&�D��W�5�1�1�1�G��F��d�;�;�;�F��M�M�'�-�(�(�(��t�e�n�G��T�E�]�F��
���w��T��2�2�2��:����G�F�O�O�v�$=�$=��F�������6�?�?�f�$�$�
�E�E�'�5�t�E�,�,�,�,�
�E�E�'�6�<�d�E�3�3�3��a�e�D�1�1�1����
��r�c��|jtur |jjt	t��fS|jj|jjjfS)a
        Return the addresses of the data and mask areas.

        Parameters
        ----------
        None

        Examples
        --------
        >>> x = np.ma.array([1, 2, 3], mask=[0, 1, 1])
        >>> x.ids()
        (166670640, 166659832) # may vary

        If the array has no mask, the address of `nomask` is returned. This address
        is typically not close to the data in memory:

        >>> x = np.ma.array([1, 2, 3])
        >>> x.ids()
        (166691080, 3083169284) # may vary

        )rqr��ctypesrm�idr�s r�r`zMaskedArray.ids�s?��,�:�����K�$�b��j�j�1�1��� �$�*�"3�"8�9�9r�c��|jdS)a�
        Return a boolean indicating whether the data is contiguous.

        Parameters
        ----------
        None

        Examples
        --------
        >>> x = np.ma.array([1, 2, 3])
        >>> x.iscontiguous()
        True

        `iscontiguous` returns one of the flags of the masked array:

        >>> x.flags
          C_CONTIGUOUS : True
          F_CONTIGUOUS : True
          OWNDATA : False
          WRITEABLE : True
          ALIGNED : True
          WRITEBACKIFCOPY : False

        �
CONTIGUOUS)r�r�s r��iscontiguouszMaskedArray.iscontiguouss��2�z�,�'�'r�c���|tjurind|i}t|j|fi|��}|�j|�d��jdd|i|���t|����}|jr|�	|��n	|rtS|S|�d��jd||d�|��t|t��r|js|r|�	|��|S)a�
        Returns True if all elements evaluate to True.

        The output array is masked where all the values along the given axis
        are masked: if the output would have been a scalar and that all the
        values are masked, then the output is `masked`.

        Refer to `numpy.all` for full documentation.

        See Also
        --------
        numpy.ndarray.all : corresponding function for ndarrays
        numpy.all : equivalent function

        Examples
        --------
        >>> np.ma.array([1,2,3]).all()
        True
        >>> a = np.ma.array([1,2,3], mask=True)
        >>> (a.all() is np.ma.masked)
        True

        r!NTr�r
r�)
rr
r"rqrNrrlr^r�rwrwr!r�r}r�rtr!r�ror�s       r�rzMaskedArray.all's��0 �2�;�.�.���Z��4J����
�D�;�;�F�;�;���;�%����D�!�!�%�:�:�4�:�6�:�:�?�?��T�
�
�K�K�A��v�
��
�
�d�#�#�#�#��
��
��H�����D����;�4�S�;�;�F�;�;�;��c�;�'�'�	&��x�
&�4�
&�����%�%�%��
r�c���|tjurind|i}t|j|fi|��}|�j|�d��jdd|i|���t|����}|jr|�	|��n	|rt}|S|�d��jd||d�|��t|t��r|js|r|�	|��|S)aS
        Returns True if any of the elements of `a` evaluate to True.

        Masked values are considered as False during computation.

        Refer to `numpy.any` for full documentation.

        See Also
        --------
        numpy.ndarray.any : corresponding function for ndarrays
        numpy.any : equivalent function

        r!NFr�r
r�)
rr
r"rqrNr!rlr^r�rwrwr!rr�s       r�r!zMaskedArray.anyOs�� �2�;�.�.���Z��4J����
�D�;�;�F�;�;���;�&����E�"�"�&�;�;�D�;�F�;�;�@�@��d���L�L�A��v�
��
�
�d�#�#�#�#��
����H�����E����<�D�c�<�<�V�<�<�<��c�;�'�'�	&��x�
&�4�
&�����%�%�%��
r�c�n�t|�d��d������S)a�

        Return the indices of unmasked elements that are not zero.

        Returns a tuple of arrays, one for each dimension, containing the
        indices of the non-zero elements in that dimension. The corresponding
        non-zero values can be obtained with::

            a[a.nonzero()]

        To group the indices by element, rather than dimension, use
        instead::

            np.transpose(a.nonzero())

        The result of this is always a 2d array, with a row for each non-zero
        element.

        Parameters
        ----------
        None

        Returns
        -------
        tuple_of_arrays : tuple
            Indices of elements that are non-zero.

        See Also
        --------
        numpy.nonzero :
            Function operating on ndarrays.
        flatnonzero :
            Return indices that are non-zero in the flattened version of the input
            array.
        numpy.ndarray.nonzero :
            Equivalent ndarray method.
        count_nonzero :
            Counts the number of non-zero elements in the input array.

        Examples
        --------
        >>> import numpy.ma as ma
        >>> x = ma.array(np.eye(3))
        >>> x
        masked_array(
          data=[[1., 0., 0.],
                [0., 1., 0.],
                [0., 0., 1.]],
          mask=False,
          fill_value=1e+20)
        >>> x.nonzero()
        (array([0, 1, 2]), array([0, 1, 2]))

        Masked elements are ignored.

        >>> x[1, 1] = ma.masked
        >>> x
        masked_array(
          data=[[1.0, 0.0, 0.0],
                [0.0, --, 0.0],
                [0.0, 0.0, 1.0]],
          mask=[[False, False, False],
                [False,  True, False],
                [False, False, False]],
          fill_value=1e+20)
        >>> x.nonzero()
        (array([0, 2]), array([0, 2]))

        Indices can also be grouped by element.

        >>> np.transpose(x.nonzero())
        array([[0, 0],
               [2, 2]])

        A common use for ``nonzero`` is to find the indices of an array, where
        a condition is True.  Given an array `a`, the condition `a` > 3 is a
        boolean array and since False is interpreted as 0, ma.nonzero(a > 3)
        yields the indices of the `a` where the condition is true.

        >>> a = ma.array([[1,2,3],[4,5,6],[7,8,9]])
        >>> a > 3
        masked_array(
          data=[[False, False, False],
                [ True,  True,  True],
                [ True,  True,  True]],
          mask=False,
          fill_value=True)
        >>> ma.nonzero(a > 3)
        (array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))

        The ``nonzero`` method of the condition array can also be called.

        >>> (a > 3).nonzero()
        (array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))

        rFr�)rrNr�r�s r�r�zMaskedArray.nonzeroms.��@�d�k�k�!�n�n�5�1�1�1�9�9�;�;�;r�r�c�B��|j}|tur:t���||||���}|�|��S|�|||���}|�|���d���d|���S)z8
        (this docstring should be overwritten)
        )�offset�axis1�axis2rt)r�r�r�rr�r
)rqr�r�r�r�rFrNr�)
r}r�r�r�rrtr�rUr�r�s
         �r�r�zMaskedArray.trace�s����

�J����;�;��W�W�]�]�&��U�'*�#�,�,�F��=�=��'�'�'��
�
�V�5��
�F�F�A��8�8�E�?�?�)�)�!�,�,�0�0�b�c�0�B�B�Br�c�(�t||||���S)a�
        a.dot(b, out=None)

        Masked dot product of two arrays. Note that `out` and `strict` are
        located in different positions than in `ma.dot`. In order to
        maintain compatibility with the functional version, it is
        recommended that the optional arguments be treated as keyword only.
        At some point that may be mandatory.

        .. versionadded:: 1.10.0

        Parameters
        ----------
        b : masked_array_like
            Inputs array.
        out : masked_array, optional
            Output argument. This must have the exact kind that would be
            returned if it was not used. In particular, it must have the
            right type, must be C-contiguous, and its dtype must be the
            dtype that would be returned for `ma.dot(a,b)`. This is a
            performance feature. Therefore, if these conditions are not
            met, an exception is raised, instead of attempting to be
            flexible.
        strict : bool, optional
            Whether masked data are propagated (True) or set to 0 (False)
            for the computation. Default is False.  Propagating the mask
            means that if a masked value appears in a row or column, the
            whole row or column is considered masked.

            .. versionadded:: 1.10.2

        See Also
        --------
        numpy.ma.dot : equivalent function

        )rt�strict)�dot)r}r�rtr�s    r�r�zMaskedArray.dot�s��J�4���F�3�3�3�3r�c�4�|tjurind|i}|j}t||fi|��}|�y|�d��j|fd|i|��}t
|dd��}	|	r8|�t|����}|�	|��n	|rt}|S|�d��j|f||d�|��}t|t��r:t|��}
|
turt|j��x}
|_||
_|S)aW
        Return the sum of the array elements over the given axis.

        Masked elements are set to 0 internally.

        Refer to `numpy.sum` for full documentation.

        See Also
        --------
        numpy.ndarray.sum : corresponding function for ndarrays
        numpy.sum : equivalent function

        Examples
        --------
        >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
        >>> x
        masked_array(
          data=[[1, --, 3],
                [--, 5, --],
                [7, --, 9]],
          mask=[[False,  True, False],
                [ True, False,  True],
                [False,  True, False]],
          fill_value=999999)
        >>> x.sum()
        25
        >>> x.sum(axis=1)
        masked_array(data=[4, 5, 16],
                     mask=[False, False, False],
               fill_value=999999)
        >>> x.sum(axis=0)
        masked_array(data=[8, 5, 12],
                     mask=[False, False, False],
               fill_value=999999)
        >>> print(type(x.sum(axis=0, dtype=np.int64)[0]))
        <class 'numpy.int64'>

        r!Nrrr��rrt)rr
rqr"rNr�r�rlr^rwrwr!rrYr�rur�r��r}r�rrtr!r�rqrrU�rndim�outmasks           r�r�zMaskedArray.sums9��N �2�;�.�.���Z��4J���
��"�5�$�9�9�&�9�9���;�'�T�[�[��^�^�'��D�D�E�D�V�D�D�F��F�F�A�.�.�E��
 ����T�$�Z�Z�0�0���"�"�7�+�+�+�+��
 ����M�#����Q���#�D�I��3�I�I�&�I�I���c�;�'�'�	#��c�l�l�G��&� � �&4�S�Y�&?�&?�?��#�)�"�G�L��
r�c�:�|�d���|||���}|�1t|t��r|�|j��|S|�t|����}|�|j��|S)a
        Return the cumulative sum of the array elements over the given axis.

        Masked values are set to 0 internally during the computation.
        However, their position is saved, and the result will be masked at
        the same locations.

        Refer to `numpy.cumsum` for full documentation.

        Notes
        -----
        The mask is lost if `out` is not a valid :class:`ma.MaskedArray` !

        Arithmetic is modular when using integer types, and no error is
        raised on overflow.

        See Also
        --------
        numpy.ndarray.cumsum : corresponding function for ndarrays
        numpy.cumsum : equivalent function

        Examples
        --------
        >>> marr = np.ma.array(np.arange(10), mask=[0,0,0,1,1,1,0,0,0,0])
        >>> marr.cumsum()
        masked_array(data=[0, 1, 3, --, --, --, 9, 16, 24, 33],
                     mask=[False, False, False,  True,  True,  True, False, False,
                           False, False],
               fill_value=999999)

        r�r�rrt)	rNrCr!rrwrorlr^rq�r}r�rrtrUs     r�rCzMaskedArray.cumsumCs���@���Q���&�&�D��3�&�G�G���?��#�{�+�+�
+�����	�*�*�*��J����T�$�Z�Z�(�(�����4�:�&�&�&��
r�c�4�|tjurind|i}|j}t||fi|��}|�y|�d��j|fd|i|��}t
|dd��}	|	r8|�t|����}|�	|��n	|rt}|S|�d��j|f||d�|��}t|t��r:t|��}
|
turt|j��x}
|_||
_|S)a�
        Return the product of the array elements over the given axis.

        Masked elements are set to 1 internally for computation.

        Refer to `numpy.prod` for full documentation.

        Notes
        -----
        Arithmetic is modular when using integer types, and no error is raised
        on overflow.

        See Also
        --------
        numpy.ndarray.prod : corresponding function for ndarrays
        numpy.prod : equivalent function
        r!Nr�rr�rr�)rr
rqr"rNr�r�rlr^rwrwr!rrYr�rur�r�r�s           r�r�zMaskedArray.prodls8��$ �2�;�.�.���Z��4J���
��"�5�$�9�9�&�9�9���;�(�T�[�[��^�^�(��E�E�U�E�f�E�E�F��F�F�A�.�.�E��
 ����T�$�Z�Z�0�0���"�"�7�+�+�+�+��
 ����M�$����Q���$�T�J��C�J�J�6�J�J���c�;�'�'�	#��c�l�l�G��&� � �&4�S�Y�&?�&?�?��#�)�"�G�L��
r�c�:�|�d���|||���}|�1t|t��r|�|j��|S|�t|����}|�|j��|S)a�
        Return the cumulative product of the array elements over the given axis.

        Masked values are set to 1 internally during the computation.
        However, their position is saved, and the result will be masked at
        the same locations.

        Refer to `numpy.cumprod` for full documentation.

        Notes
        -----
        The mask is lost if `out` is not a valid MaskedArray !

        Arithmetic is modular when using integer types, and no error is
        raised on overflow.

        See Also
        --------
        numpy.ndarray.cumprod : corresponding function for ndarrays
        numpy.cumprod : equivalent function
        r�r�)rNrBr!rrwrqrlr^r�s     r�rBzMaskedArray.cumprod�s���,���Q���'�'�T��C�'�H�H���?��#�{�+�+�
,�����
�+�+�+��J����T�$�Z�Z�(�(�����4�:�&�&�&��
r�c�,��|tjurind|i}|jtur#t	��jd||d�|��d}n�d}|�t
|jjtj
tjf��rtjd��}n:t
|jjtj
��rtjd��}d}|jd||d�|��}|jdd	|i|��}	|	jdkr|	d
krt"}n+|r!|j�|dz|	z��}n|dz|	z}|�e||_t'|t(��rGt+|��}
|
turt-|j��x}
|_t+|��|
_|S|S)a�
        Returns the average of the array elements along given axis.

        Masked entries are ignored, and result elements which are not
        finite will be masked.

        Refer to `numpy.mean` for full documentation.

        See Also
        --------
        numpy.ndarray.mean : corresponding function for ndarrays
        numpy.mean : Equivalent function
        numpy.ma.average : Weighted average.

        Examples
        --------
        >>> a = np.ma.array([1,2,3], mask=[False, False, True])
        >>> a
        masked_array(data=[1, 2, --],
                     mask=[False, False,  True],
               fill_value=999999)
        >>> a.mean()
        1.5

        r!r�r�FN�f8�f4Tr�rr�)rr
rqr�r�r�rarr^�ntypes�integerr	�mu�float16r�rAr�rwr�r!rrYru)r}r�rrtr!r�rU�is_float16_result�dsum�cntr�r�s           �r�r�zMaskedArray.mean�s����4 �2�;�.�.���Z��4J���:����!�U�W�W�\�C�t�5�C�C�F�C�C�B�G�F�F� %���}��d�j�o�����/M�N�N�-��H�T�N�N�E�E���
����@�@�-��H�T�N�N�E�(,�%��4�8�=��U�=�=�f�=�=�D��$�*�1�1�$�1�&�1�1�C��y�B���C�1�H�H����"�
)��������S��9�9������S����?��C�H��#�{�+�+�
/�!�#�,�,���f�$�$�*8���*C�*C�C�G�c�i�&�v������J��
r�c�b�|�||��}|s||z
S|t||��z
S)a�
        Compute the anomalies (deviations from the arithmetic mean)
        along the given axis.

        Returns an array of anomalies, with the same shape as the input and
        where the arithmetic mean is computed along the given axis.

        Parameters
        ----------
        axis : int, optional
            Axis over which the anomalies are taken.
            The default is to use the mean of the flattened array as reference.
        dtype : dtype, optional
            Type to use in computing the variance. For arrays of integer type
             the default is float32; for arrays of float types it is the same as
             the array type.

        See Also
        --------
        mean : Compute the mean of the array.

        Examples
        --------
        >>> a = np.ma.array([1,2,3])
        >>> a.anom()
        masked_array(data=[-1.,  0.,  1.],
                     mask=False,
               fill_value=1e+20)

        )r�r)r}r�rr�s    r�rzMaskedArray.anom�s=��>
�I�I�d�E�"�"���	/��!�8�O��+�a��.�.�.�.r�c�"��|tjurind|i}|jturYt	��jd||||d�|��d}|�1t
|t��r|�t��|S|S|j	dd|i|��|z
}||�
||d���z
}	t|��rtj
|	��dz}	n|	|	z}	t|	j|fi|��|���t#|����}
|
jr@t'|jj|fi|��|d	k��|
_|
�|��n|t-|
��rmt.}
|�dt
|t��rd	|_|�d��n0|jjd
vrd}t7|���tj|_|S|�8|
|_t
|t��r|�|
j��|S|
S)au
        Returns the variance of the array elements along given axis.

        Masked entries are ignored, and result elements which are not
        finite will be masked.

        Refer to `numpy.var` for full documentation.

        See Also
        --------
        numpy.ndarray.var : corresponding function for ndarrays
        numpy.var : Equivalent function
        r!)r�rrt�ddofr�Nr�T�r!r�r�biu�>Masked data information would be lost in one or more location.)rr
rqr�r�r�r!rrwrAr�rr�rrHr�rlr^r�rvrr�rYrwr�rr(rr�ro)
r}r�rrtr�r!r�rGr��danom�dvarr�r�s
            �r�r�zMaskedArray.vars?��� �2�;�.�.���Z��4J���:�����%�'�'�+�(�4�u�#�D�(�(� &�(�(�(*�,�C����c�;�/�/�,��O�O�F�+�+�+��
��J��d�j�-�-�d�-�f�-�-��4���t�y�y��u�t�y�<�<�<������	��N�5�)�)�Q�.�E�E��U�N�E��i�e�i��/�/��/�/��5�5�:�:�4��:�:�F�F���9�	� ������!?�!?��!?�!?�#��(�L�L�D�J����d�#�#�#�#�
�T�]�]�
	��D����c�;�/�/�&� �C�H��O�O�D�)�)�)�)��Y�^�u�,�,�.�F�#�F�+�+�+�!�v�C�H��
��?��C�H��#�{�+�+�
+�����	�*�*�*��J��r�c��|tjurind|i}|j||||fi|��}|tur+|�tj|d|d���|St|��}|S)a>
        Returns the standard deviation of the array elements along given axis.

        Masked entries are ignored.

        Refer to `numpy.std` for full documentation.

        See Also
        --------
        numpy.ndarray.std : corresponding function for ndarrays
        numpy.std : Equivalent function
        r!Ng�?r��rtr�)rr
r�rwr�r�)r}r�rrtr�r!r�r�s        r�r�zMaskedArray.stdQs{�� �2�;�.�.���Z��4J���t�x��e�S�$�9�9�&�9�9���v��������c�s�H�=�=�=�=��
���:�:�D��r�c�Z�|j�||����t|����}|jdkr"|j|_|�|��n|jrt}|�|St|t��r|�
|j��|S)a
        Return each element rounded to the given number of decimals.

        Refer to `numpy.around` for full documentation.

        See Also
        --------
        numpy.ndarray.round : corresponding function for ndarrays
        numpy.around : equivalent function
        )�decimalsrtr)rjr�rlr^r�rqr�rwr!rrw)r}r�rtrUs    r�r�zMaskedArray.roundis�����!�!�8��!�=�=�B�B�4��:�:�N�N���;��?�?��:�F�L�����%�%�%�%�
�Z�	��F��;��M��c�;�'�'�	(��O�O�D�J�'�'�'��
r�c�>�|tjurt|��}|�R|rAtj|jtj��r
tj}nt|��}nt|��}|�	|��}|�
|||���S)a!	
        Return an ndarray of indices that sort the array along the
        specified axis.  Masked values are filled beforehand to
        `fill_value`.

        Parameters
        ----------
        axis : int, optional
            Axis along which to sort. If None, the default, the flattened array
            is used.

            ..  versionchanged:: 1.13.0
                Previously, the default was documented to be -1, but that was
                in error. At some future date, the default will change to -1, as
                originally intended.
                Until then, the axis should be given explicitly when
                ``arr.ndim > 1``, to avoid a FutureWarning.
        kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, optional
            The sorting algorithm used.
        order : list, optional
            When `a` is an array with fields defined, this argument specifies
            which fields to compare first, second, etc.  Not all fields need be
            specified.
        endwith : {True, False}, optional
            Whether missing values (if any) should be treated as the largest values
            (True) or the smallest values (False)
            When the array contains unmasked values at the same extremes of the
            datatype, the ordering of these values and the masked values is
            undefined.
        fill_value : scalar or None, optional
            Value used internally for the masked values.
            If ``fill_value`` is not None, it supersedes ``endwith``.

        Returns
        -------
        index_array : ndarray, int
            Array of indices that sort `a` along the specified axis.
            In other words, ``a[index_array]`` yields a sorted `a`.

        See Also
        --------
        ma.MaskedArray.sort : Describes sorting algorithms used.
        lexsort : Indirect stable sort with multiple keys.
        numpy.ndarray.sort : Inplace sort.

        Notes
        -----
        See `sort` for notes on the different sorting algorithms.

        Examples
        --------
        >>> a = np.ma.array([3,2,1], mask=[False, False, True])
        >>> a
        masked_array(data=[3, 2, --],
                     mask=[False, False,  True],
               fill_value=999999)
        >>> a.argsort()
        array([1, 0, 2])

        N�r�r(r�)rr
r�rBrrCr�r�r�rNr-)r}r�r(r��endwithrMrNs       r�r-zMaskedArray.argsort�s���@�2�;���*�4�0�0�D����
6��=���R�[�9�9�:�!#��J�J�!3�D�!9�!9�J�J�/��5�5�
����Z�(�(���~�~�4�d�%�~�@�@�@r�r�c���|�t|��}|�|���t��}|tjurdnt
|��}|�|||���S)a<
        Return array of indices to the minimum values along the given axis.

        Parameters
        ----------
        axis : {None, integer}
            If None, the index is into the flattened array, otherwise along
            the specified axis
        fill_value : scalar or None, optional
            Value used to fill in the masked values.  If None, the output of
            minimum_fill_value(self._data) is used instead.
        out : {None, array}, optional
            Array into which the result can be placed. Its type is preserved
            and it must be of the right shape to hold the output.

        Returns
        -------
        ndarray or scalar
            If multi-dimension input, returns a new ndarray of indices to the
            minimum values along the given axis.  Otherwise, returns a scalar
            of index to the minimum values along the given axis.

        Examples
        --------
        >>> x = np.ma.array(np.arange(4), mask=[1,1,0,0])
        >>> x.shape = (2,2)
        >>> x
        masked_array(
          data=[[--, --],
                [2, 3]],
          mask=[[ True,  True],
                [False, False]],
          fill_value=999999)
        >>> x.argmin(axis=0, fill_value=-1)
        array([0, 0])
        >>> x.argmin(axis=0, fill_value=9)
        array([1, 1])

        NF�rtr!)r�rNrlrrr
rr,�r}r�rMrtr!r�s      r�r,zMaskedArray.argmin�sj��R��+�D�1�1�J��K�K�
�#�#�(�(��1�1��$���3�3�5�5��h�����x�x��#��x�9�9�9r�c��|�t|j��}|�|���t��}|t
jurdnt|��}|�|||���S)a�
        Returns array of indices of the maximum values along the given axis.
        Masked values are treated as if they had the value fill_value.

        Parameters
        ----------
        axis : {None, integer}
            If None, the index is into the flattened array, otherwise along
            the specified axis
        fill_value : scalar or None, optional
            Value used to fill in the masked values.  If None, the output of
            maximum_fill_value(self._data) is used instead.
        out : {None, array}, optional
            Array into which the result can be placed. Its type is preserved
            and it must be of the right shape to hold the output.

        Returns
        -------
        index_array : {integer_array}

        Examples
        --------
        >>> a = np.arange(6).reshape(2,3)
        >>> a.argmax()
        5
        >>> a.argmax(0)
        array([1, 1, 1])
        >>> a.argmax(1)
        array([2, 2])

        NFr�)	r�rjrNrlrrr
rr+r�s      r�r+zMaskedArray.argmaxsl��B��+�D�J�7�7�J��K�K�
�#�#�(�(��1�1��$���3�3�5�5��h�����x�x��#��x�9�9�9r�r�c���|jturtj||||���dS|turdS|�|||||���}t
j|||���|d<dS)a


        Sort the array, in-place

        Parameters
        ----------
        a : array_like
            Array to be sorted.
        axis : int, optional
            Axis along which to sort. If None, the array is flattened before
            sorting. The default is -1, which sorts along the last axis.
        kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, optional
            The sorting algorithm used.
        order : list, optional
            When `a` is a structured array, this argument specifies which fields
            to compare first, second, and so on.  This list does not need to
            include all of the fields.
        endwith : {True, False}, optional
            Whether missing values (if any) should be treated as the largest values
            (True) or the smallest values (False)
            When the array contains unmasked values sorting at the same extremes of the
            datatype, the ordering of these values and the masked values is
            undefined.
        fill_value : scalar or None, optional
            Value used internally for the masked values.
            If ``fill_value`` is not None, it supersedes ``endwith``.

        Returns
        -------
        sorted_array : ndarray
            Array of the same type and shape as `a`.

        See Also
        --------
        numpy.ndarray.sort : Method to sort an array in-place.
        argsort : Indirect sort.
        lexsort : Indirect stable sort on multiple keys.
        searchsorted : Find elements in a sorted array.

        Notes
        -----
        See ``sort`` for notes on the different sorting algorithms.

        Examples
        --------
        >>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
        >>> # Default
        >>> a.sort()
        >>> a
        masked_array(data=[1, 3, 5, --, --],
                     mask=[False, False, False,  True,  True],
               fill_value=999999)

        >>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
        >>> # Put missing values in the front
        >>> a.sort(endwith=False)
        >>> a
        masked_array(data=[--, --, 1, 3, 5],
                     mask=[ True,  True, False, False, False],
               fill_value=999999)

        >>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
        >>> # fill_value takes over endwith
        >>> a.sort(endwith=False, fill_value=3)
        >>> a
        masked_array(data=[1, --, --, 3, 5],
                     mask=[False,  True,  True, False, False],
               fill_value=999999)

        r�N)r�r(r�rMr�r�.)rqr�rr�rwr-r�take_along_axis)r}r�r(r�r�rM�sidxs       r�r�zMaskedArray.sort(s���N�:�����L��D�t�5�A�A�A�A��F��6�>�>��F��|�|��D��'1�7��D�D���&�t�T��=�=�=��S�	�	�	r�c��|tjurind|i}|j}t||fi|��}|�t	|��}|��|�|��jd||d�|���t|����}|j	r9|�
|��|j	rtj||j|���n	|rt}|S|�|��jd||d�|��}t|t��r;t!|��}	|	t"urt%|j��x}	|_||	_n@|jjdvrd}
t/|
���tj|tj|���|S)as	
        Return the minimum along a given axis.

        Parameters
        ----------
        axis : None or int or tuple of ints, optional
            Axis along which to operate.  By default, ``axis`` is None and the
            flattened input is used.
            .. versionadded:: 1.7.0
            If this is a tuple of ints, the minimum is selected over multiple
            axes, instead of a single axis or all the axes as before.
        out : array_like, optional
            Alternative output array in which to place the result.  Must be of
            the same shape and buffer length as the expected output.
        fill_value : scalar or None, optional
            Value used to fill in the masked values.
            If None, use the output of `minimum_fill_value`.
        keepdims : bool, optional
            If this is set to True, the axes which are reduced are left
            in the result as dimensions with size one. With this option,
            the result will broadcast correctly against the array.

        Returns
        -------
        amin : array_like
            New array holding the result.
            If ``out`` was specified, ``out`` is returned.

        See Also
        --------
        ma.minimum_fill_value
            Returns the minimum filling value for a given datatype.

        Examples
        --------
        >>> import numpy.ma as ma
        >>> x = [[1., -2., 3.], [0.2, -0.7, 0.1]]
        >>> mask = [[1, 1, 0], [0, 0, 1]]
        >>> masked_x = ma.masked_array(x, mask)
        >>> masked_x
        masked_array(
          data=[[--, --, 3.0],
                [0.2, -0.7, --]],
          mask=[[ True,  True, False],
                [False, False,  True]],
          fill_value=1e+20)
        >>> ma.min(masked_x)
        -0.7
        >>> ma.min(masked_x, axis=-1)
        masked_array(data=[3.0, -0.7],
                     mask=[False, False],
                fill_value=1e+20)
        >>> ma.min(masked_x, axis=0, keepdims=True)
        masked_array(data=[[0.2, -0.7, 3.0]],
                     mask=[[False, False, False]],
                fill_value=1e+20)
        >>> mask = [[1, 1, 1,], [1, 1, 1]]
        >>> masked_x = ma.masked_array(x, mask)
        >>> ma.min(masked_x, axis=0)
        masked_array(data=[--, --, --],
                     mask=[ True,  True,  True],
                fill_value=1e+20,
                    dtype=float64)
        r!Nr
r�r�r�r�)rr
rqr"r�rNr�rlr^r�rwr�rMrwr!rrYr�rur�r�rr(rr��r}r�rtrMr!r�rqrrUr�r�s           r�r�zMaskedArray.min{s���B �2�;�.�.���Z��4J���
��"�5�$�9�9�&�9�9����+�D�1�1�J��;�0�T�[�[��,�,�0�.��s�.�.�&,�.�.�.2�d�4��:�:�.>�.>�
��{�
 ��"�"�7�+�+�+��<�H��I�f�f�&7�w�G�G�G�G���
 ����M�,����Z�(�(�,�J�$�C�J�J�6�J�J���c�;�'�'�
	2��c�l�l�G��&� � �&4�S�Y�&?�&?�?��#�)�"�G�L�L��y�~��&�&�&����'�'�'��I�c�2�6��1�1�1�1��
r�c��|tjurind|i}|j}t||fi|��}|�t	|��}|��|�|��jd||d�|���t|����}|j	r9|�
|��|j	rtj||j|���n	|rt}|S|�|��jd||d�|��}t|t��r;t!|��}	|	t"urt%|j��x}	|_||	_n@|jjdvrd}
t/|
���tj|tj|���|S)a�	
        Return the maximum along a given axis.

        Parameters
        ----------
        axis : None or int or tuple of ints, optional
            Axis along which to operate.  By default, ``axis`` is None and the
            flattened input is used.
            .. versionadded:: 1.7.0
            If this is a tuple of ints, the maximum is selected over multiple
            axes, instead of a single axis or all the axes as before.
        out : array_like, optional
            Alternative output array in which to place the result.  Must
            be of the same shape and buffer length as the expected output.
        fill_value : scalar or None, optional
            Value used to fill in the masked values.
            If None, use the output of maximum_fill_value().
        keepdims : bool, optional
            If this is set to True, the axes which are reduced are left
            in the result as dimensions with size one. With this option,
            the result will broadcast correctly against the array.

        Returns
        -------
        amax : array_like
            New array holding the result.
            If ``out`` was specified, ``out`` is returned.

        See Also
        --------
        ma.maximum_fill_value
            Returns the maximum filling value for a given datatype.

        Examples
        --------
        >>> import numpy.ma as ma
        >>> x = [[-1., 2.5], [4., -2.], [3., 0.]]
        >>> mask = [[0, 0], [1, 0], [1, 0]]
        >>> masked_x = ma.masked_array(x, mask)
        >>> masked_x
        masked_array(
          data=[[-1.0, 2.5],
                [--, -2.0],
                [--, 0.0]],
          mask=[[False, False],
                [ True, False],
                [ True, False]],
          fill_value=1e+20)
        >>> ma.max(masked_x)
        2.5
        >>> ma.max(masked_x, axis=0)
        masked_array(data=[-1.0, 2.5],
                     mask=[False, False],
               fill_value=1e+20)
        >>> ma.max(masked_x, axis=1, keepdims=True)
        masked_array(
          data=[[2.5],
                [-2.0],
                [0.0]],
          mask=[[False],
                [False],
                [False]],
          fill_value=1e+20)
        >>> mask = [[1, 1], [1, 1], [1, 1]]
        >>> masked_x = ma.masked_array(x, mask)
        >>> ma.max(masked_x, axis=1)
        masked_array(data=[--, --, --],
                     mask=[ True,  True,  True],
               fill_value=1e+20,
                    dtype=float64)
        r!Nr
r�r�r�r�)rr
rqr"r�rNr�rlr^r�rwr�rMrwr!rrYr�rur�r�rr(rr�r�s           r�r�zMaskedArray.max�s���P �2�;�.�.���Z��4J���
��"�5�$�9�9�&�9�9����+�D�1�1�J��;�0�T�[�[��,�,�0�.��s�.�.�&,�.�.�.2�d�4��:�:�.>�.>�
��{�
 ��"�"�7�+�+�+��<�H��I�f�f�&7�w�G�G�G�G���
 ����M�,����Z�(�(�,�J�$�C�J�J�6�J�J���c�;�'�'�	2��c�l�l�G��&� � �&4�S�Y�&?�&?�?��#�)�"�G�L�L��y�~��&�&�&����'�'�'��I�c�2�6��1�1�1�1��
r�c��|�5|�|||���}||�|||���z}|S|�||||���|_|�|||���}tj|||d���|S)a�

        Return (maximum - minimum) along the given dimension
        (i.e. peak-to-peak value).

        .. warning::
            `ptp` preserves the data type of the array. This means the
            return value for an input of signed integers with n bits
            (e.g. `np.int8`, `np.int16`, etc) is also a signed integer
            with n bits.  In that case, peak-to-peak values greater than
            ``2**(n-1)-1`` will be returned as negative values. An example
            with a work-around is shown below.

        Parameters
        ----------
        axis : {None, int}, optional
            Axis along which to find the peaks.  If None (default) the
            flattened array is used.
        out : {None, array_like}, optional
            Alternative output array in which to place the result. It must
            have the same shape and buffer length as the expected output
            but the type will be cast if necessary.
        fill_value : scalar or None, optional
            Value used to fill in the masked values.
        keepdims : bool, optional
            If this is set to True, the axes which are reduced are left
            in the result as dimensions with size one. With this option,
            the result will broadcast correctly against the array.

        Returns
        -------
        ptp : ndarray.
            A new array holding the result, unless ``out`` was
            specified, in which case a reference to ``out`` is returned.

        Examples
        --------
        >>> x = np.ma.MaskedArray([[4, 9, 2, 10],
        ...                        [6, 9, 7, 12]])

        >>> x.ptp(axis=1)
        masked_array(data=[8, 6],
                     mask=False,
               fill_value=999999)

        >>> x.ptp(axis=0)
        masked_array(data=[2, 0, 5, 2],
                     mask=False,
               fill_value=999999)

        >>> x.ptp()
        10

        This example shows that a negative value can be returned when
        the input is an array of signed integers.

        >>> y = np.ma.MaskedArray([[1, 127],
        ...                        [0, 127],
        ...                        [-1, 127],
        ...                        [-2, 127]], dtype=np.int8)
        >>> y.ptp(axis=1)
        masked_array(data=[ 126,  127, -128, -127],
                     mask=False,
               fill_value=999999,
                    dtype=int8)

        A work-around is to use the `view()` method to view the result as
        unsigned integers with the same bit width:

        >>> y.ptp(axis=1).view(np.uint8)
        masked_array(data=[126, 127, 128, 129],
                     mask=False,
               fill_value=999999,
                    dtype=uint8)
        N)r�rMr!)r�rtrMr!r�r�)r�r�r�rr�)r}r�rtrMr!rU�	min_values       r�r�zMaskedArray.ptpIs���V�;��X�X�4�J�'/��1�1�F��d�h�h�D�Z�(0��2�2�
2�F��M��8�8��3�:�%-��/�/����H�H�$�:�&.��0�0�	�
��C���X�>�>�>�>��
r�c�~��tjd|jj�d�d���t	��j|i|��S)Nz3Warning: 'partition' will ignore the 'mask' of the r0r�r�)r�r�r�r�r��	partition�r}r�r�r�s   �r�r�zMaskedArray.partition�sY����
�;� $�� 7�;�;�;�!"�	$�	$�	$�	$�!�u�w�w� �$�1�&�1�1�1r�c�~��tjd|jj�d�d���t	��j|i|��S)Nz6Warning: 'argpartition' will ignore the 'mask' of the r0r�r�)r�r�r�r�r��argpartitionr�s   �r�r�zMaskedArray.argpartition�sY����
�;� $�� 7�;�;�;�!"�	$�	$�	$�	$�$�u�w�w�#�T�4�V�4�4�4r�c���|j|j}}t|��}t|��}|tur|�d��}|�2|�|||���d�|��}ntj|||||���t|t��r>|tur|}	n|�|||���}	|	|z}	|�|	��|dS)z	
        rN)r�r�.)r�r�rtr�)rjrqr^rYr�rNr�rlrr!rrw)
r}rar�rtr�rjrqre�maskindicesr�s
          r�r�zMaskedArray.take�s����*�d�j����4�j�j���g�&�&���f�$�$��n�n�Q�'�'�G��;��*�*�W�4�d�*�;�;�C�@�E�E�c�J�J�C�C��G�E�7��D�c�B�B�B�B��c�;�'�'�	%�����%����*�*�W�4�d�*�C�C���;�&���O�O�G�$�$�$��2�w�r�r=rF�flattenr�r�r�c�*�|���Sr)r�r�s r��<lambda>zMaskedArray.<lambda>�s��4�>�>�#3�#3�r�r�c�L�|j}|tur|j���S|�'|�|�����S|jj}|rN|j�d�|D����}|D]}d||||<�|���S|turdgS|j}tj
|j���t���}d||���<||_|���S)aP
        Return the data portion of the masked array as a hierarchical Python list.

        Data items are converted to the nearest compatible Python type.
        Masked values are converted to `fill_value`. If `fill_value` is None,
        the corresponding entries in the output list will be ``None``.

        Parameters
        ----------
        fill_value : scalar, optional
            The value to use for invalid entries. Default is None.

        Returns
        -------
        result : list
            The Python list representation of the masked array.

        Examples
        --------
        >>> x = np.ma.array([[1,2,3], [4,5,6], [7,8,9]], mask=[0] + [1,0]*4)
        >>> x.tolist()
        [[1, None, 3], [None, 5, None], [7, None, 9]]
        >>> x.tolist(-999)
        [[1, -999, 3], [-999, 5, -999], [7, -999, 9]]

        Nc� �g|]}|tf��Sr�)rJrs  r�rz&MaskedArray.tolist.<locals>.<listcomp>�s��'C�'C�'C���F��'C�'C�'Cr�r)
rqr�rj�tolistrNrrr�r�rrr�rJ)r}rMrqrrUr�rss       r�rzMaskedArray.tolist�s��6�
���F�?�?��:�$�$�&�&�&��!��;�;�z�*�*�1�1�3�3�3��
� ���	#��Z�&�&�'C�'C�U�'C�'C�'C�D�D�F��
+�
+��&*��q�	�%��(�#�#��=�=�?�?�"��F�?�?��6�M��:����$�*�*�*�,�,�F�;�;�;�� $��u�{�{�}�}������}�}���r�c�h�tjdtd���|�||���S)z�
        A compatibility alias for `tobytes`, with exactly the same behavior.

        Despite its name, it returns `bytes` not `str`\ s.

        .. deprecated:: 1.19.0
        z0tostring() is deprecated. Use tobytes() instead.r�r�r�)r�r�r�tobytes�r}rMr�s   r��tostringzMaskedArray.tostrings=��	�
�>��1�	.�	.�	.�	.��|�|�J�e�|�4�4�4r�c�T�|�|���|���S)a�
        Return the array data as a string containing the raw bytes in the array.

        The array is filled with a fill value before the string conversion.

        .. versionadded:: 1.9.0

        Parameters
        ----------
        fill_value : scalar, optional
            Value used to fill in the masked values. Default is None, in which
            case `MaskedArray.fill_value` is used.
        order : {'C','F','A'}, optional
            Order of the data item in the copy. Default is 'C'.

            - 'C'   -- C order (row major).
            - 'F'   -- Fortran order (column major).
            - 'A'   -- Any, current order of array.
            - None  -- Same as 'A'.

        See Also
        --------
        numpy.ndarray.tobytes
        tolist, tofile

        Notes
        -----
        As for `ndarray.tobytes`, information about the shape, dtype, etc.,
        but also about `fill_value`, will be lost.

        Examples
        --------
        >>> x = np.ma.array(np.array([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]])
        >>> x.tobytes()
        b'\x01\x00\x00\x00\x00\x00\x00\x00?B\x0f\x00\x00\x00\x00\x00?B\x0f\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00'

        r�)rNr	r
s   r�r	zMaskedArray.tobytess(��L�{�{�:�&�&�.�.�U�.�;�;�;r�r��%sc� �td���)z�
        Save a masked array to a file in binary format.

        .. warning::
          This function is not implemented yet.

        Raises
        ------
        NotImplementedError
            When `tofile` is called.

        z)MaskedArray.tofile() not implemented yet.r�)r}�fid�sepr(s    r��tofilezMaskedArray.tofile;s��"�"M�N�N�Nr�c���|j}|j}|�t|j|��}|jj}t	j|jd|fd|fg���}|j|d<|j|d<|S)a�
        Transforms a masked array into a flexible-type array.

        The flexible type array that is returned will have two fields:

        * the ``_data`` field stores the ``_data`` part of the array.
        * the ``_mask`` field stores the ``_mask`` part of the array.

        Parameters
        ----------
        None

        Returns
        -------
        record : ndarray
            A new flexible-type `ndarray` with two fields: the first element
            containing a value, the second element containing the corresponding
            mask boolean. The returned record shape matches self.shape.

        Notes
        -----
        A side-effect of transforming a masked array into a flexible `ndarray` is
        that meta information (``fill_value``, ...) will be lost.

        Examples
        --------
        >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
        >>> x
        masked_array(
          data=[[1, --, 3],
                [--, 5, --],
                [7, --, 9]],
          mask=[[False,  True, False],
                [ True, False,  True],
                [False,  True, False]],
          fill_value=999999)
        >>> x.toflex()
        array([[(1, False), (2,  True), (3, False)],
               [(4,  True), (5, False), (6,  True)],
               [(7, False), (8,  True), (9, False)]],
              dtype=[('_data', '<i8'), ('_mask', '?')])

        Nrjrq)r�r)rrqrur�rrrj)r}�ddtyperqr��records     r��toflexzMaskedArray.toflexJs}��Z����
���=�"�4�:�v�6�6�E���!����$�*�$+�V�#4�w��6G�"H�J�J�J���*��w���*��w���
r�c����d|jj}t�����d}|t	|���|��|jfzS)zWReturn the internal state of the masked array, for pickling
        purposes.

        �CFr�)r�r�r��
__reduce__rZr	r�)r}�cf�
data_stater�s   �r��__getstate__zMaskedArray.__getstate__�sV���
�$�*�.�
!���W�W�'�'�)�)�!�,�
��\�$�/�/�7�7��;�;�T�=M�N�N�Nr�c����|\}}}}}}}t���||||f��|j�|t|��||f��||_dS)akRestore the internal state of the masked array, for
        pickling purposes.  ``state`` is typically the output of the
        ``__getstate__`` output, and is a 5-tuple:

        - class name
        - a tuple giving the shape of the data
        - a typecode for the data
        - a binary string for the data
        - a binary string for the mask.

        N)r��__setstate__rqrtrM)
r}�stater�shp�typ�isf�raw�msk�flvr�s
         �r�rzMaskedArray.__setstate__�sl���-2�)��C��c�3��S�
�����c�3��S�1�2�2�2��
����o�c�&:�&:�C�� E�F�F�F�����r�c�V�t|j|jddf|���fS)z6Return a 3-tuple for pickling a MaskedArray.

        r�r�)�_mareconstructr�r�rr�s r�rzMaskedArray.__reduce__�s0�������$��=��!�!�#�#�%�	%r�c�@�ddlm}t�t	|��|d���}|�i}||t|��<|j���D]\}}|||��|j|<�|jj	r||j
��|j
d<|S)Nr)�deepcopyTr�.)r=r(rr�r^r�r�r�r�	hasobjectrj)r}�memor(�copiedr�vs      r��__deepcopy__zMaskedArray.__deepcopy__�s���!�!�!�!�!�!��$�$�T�$�Z�Z��D�$�A�A���<��D���R��X�X���m�)�)�+�+�	3�	3�F�Q��!)��!�T�!2�!2�F�O�A���
�:��	7� (���� 6� 6�F�L����
r�r)NNN�F�NN�r�)TF�r�)rrr�NN)NFr��r�NNTN)NNNF�NNr�)Nr�)r�r
)�r�r�r�r�r<r��_defaultmask�_defaulthardmaskrr�r
rr�r�r�r�rlr�rr�r��propertyr�setterr�rw�	_set_maskror�r]r�r�r�r�rEr�r�rjrmr�rMr�rV�fsetr�rNr9r8rr�r[r@rPrSrVrYr]r`rcrergrirkrmrorrrtrwryr{r}rr�r�r�r�r�r�r�r�r�r��get_imagr��get_realr
rAr�r�r�r�r`r�rr!r�r�r�r�rCr�r�rBr�rr�r�r�r-r,r+r�r�r�r�r�r�r�r}r=rFrr�r�r��Tr�rrr	rr�	torecordsrrrr-r�r�s@r�rr�
s�
�������b�b�H���L����J��L��O��V�4�e��!����t�4�M�M�M�M�`���4[C�[C�[C�z6�6�6�6�pX�X�X�X�t|�|�|�B�R�[�h��1�1�1�C�C�2�1�C�L������X���\�	�	�	�	��\�	�������X���\�*�*�*�*��\�*�C�C�C�C�J�I�
�!�!��X�!�
�[� � ��[� ��@�@��X�@�$��P�P���P����$���$�)�)��X�)�V���$� � ��X� ����>����X��3�3�3�"
�H�)�$�$�$�E��8��#�#�#�D�
�$�$��X�$�
�[����[���& �& ��X�& �P��%�%�%���%�& �_�N��_�N�N�N�N�N�`���6F�F�F�F�P���>0�0�0�R%�R%�R%�h'�'�'�C�C�C�J4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4� � � � � � �%�%�%�%�%�%�%�%�%�%�%�%�#�#�#�(�(�(�(�(�(�)�)�)�)�)�)�"�"�"�"�"�"����$���"���"���&���&���&���*"�"�"�
 �
 �
 �����X��0�y�H�
����X��0�y�H����a<�a<�a<�a<�F;�;�;�;�|@�@�@�D!�!�!�!�$S�S�S�S�j:�:�:�4(�(�(�6����&�&�&�&�P��������<`<�`<�`<�DC�C�C�C�C�C��M�)�E�M�%4�%4�%4�%4�N�4�T�B�K�<�<�<�<�|'�'�'�'�R�D�d�R�[�'�'�'�'�P�G�����>�D�d�R�[�5�5�5�5�5�5�n#/�#/�#/�#/�J�4�T���[�=�=�=�=�=�=�|�&�.�C�K��4�T���[�����0����2�;�T����NA�NA�NA�NA�`-:���-:�-:�-:�-:�-:�^%:���%:�%:�%:�%:�%:�N.2�&*�Q>�Q>�Q>�Q>�f��$���a�a�a�a�F��$���i�i�i�i�VV�V�V�V�p2�2�2�2�2�5�5�5�5�5�����6�<����D��|�J�'�'�H��l�9�%�%�G�
�\�(�
#�
#�F��l�9�%�%�G��|�J�'�'�H���3�3�4�4�4�A���[�)�)�I�1�1�1�1�f
5�
5�
5�
5�&<�&<�&<�&<�P
O�
O�
O�
O�9�9�9�t�I�O�O�O�O�O������"%�%�%��������r�rc��tj|||��}tjt|t|����}|�||||���S)zbInternal function that builds a new MaskedArray from the
    information stored in a pickle.

    )ror)rr�rt)rr��	baseshape�basetyperjrqs      r�r&r&�sL��

�O�I�y�(�;�;�E��O�G�Y���0I�0I�J�J�E��?�?�7�E��X�?�G�G�Gr�c�z��eZdZdZedddddfd�Ze�fd���Zd�Zd�Z	�fd	�Z
e
Zd
�Zd�Z
dd�Zd
�Z�xZS)r�zN
    Fake a 'void' object to use for masked array with structured dtypes.
    NFTc��tj||||���}|�|��}||_|tur}t|tj��r||_n[	tj|��|_n@#t$r3t|��}	tj||	���d|_YnwxYw|�||_
|S)N)r=rirrr�)rrrlr�r�r!rHrqr�rtrM)
r}rmrorrMr�r=rirjr�s
          r�r�z
mvoid.__new__�s������D��U�C�C�C���
�
�4� � ��"����v����$���(�(�	
C�"����C�"$�'�$�-�-�E�K�K�� �C�C�C�,�U�3�3�F�"$�(�4�v�">�">�">�r�"B�E�K�K�K�C�����!�)�E���s�!A;�;:B8�7B8c�6��t��jdS)Nr�)r�rjr�s �r�rjzmvoid._data�s����w�w�}�R� � r�c��|j}t||t��r4t|j||||j||j���S|tur||rtS|j|S)z!
        Get the index.

        )rmrorMr�)	rqr!rrxrjr�r�r�rw)r}r�r�s   r�r�zmvoid.__getitem__�s��

�J���a��g�w�'�'�	*� ��Z��%�A�d�G��+�D�1��.�*�*�*�
*�
�F�?�?�q��w�?��M��z�$��r�c��||j|<|jr&|j|xxt|dd��zcc<dSt|dd��|j|<dS)NrqF)rjr�rqr�)r}r�r-s   r�r�zmvoid.__setitem__�sf�� ��
�4���>�	>��J�t������w�� >� >�>������&�u�g�u�=�=�D�J�t���r�c�$��|j}|turt|j��St	|jjd��}t
��j}|�|��}t||jt��t|��S)Nr�)
rqr�r+rjr�rr�r�r]r�)r}r�r�data_arrrIr�s     �r�r�z
mvoid.__str__�sq����J����;�;��t�z�?�?�"�&�t�z�'7��=�=���7�7�=���o�o�f�%�%���s�D�J�0C�D�D�D��3�x�x�r�c#�K�|j|j}}|tur
|Ed{V��dSt||��D]\}}|r
tV��|V��dS)zDefines an iterator for mvoidN)rjrqr�r=rw)r}rjrqr�r�s     r�rzmvoid.__iter__s�����*�d�j����F�?�?������������e�U�+�+�
�
���A��� �L�L�L�L��G�G�G�G�	
�
r�c�4�|j���Sr)rj�__len__r�s r�rJz
mvoid.__len__s���z�!�!�#�#�#r�c�R�t|���|��dS)aA
        Return a copy with masked fields filled with a given value.

        Parameters
        ----------
        fill_value : array_like, optional
            The value to use for invalid entries. Can be scalar or
            non-scalar. If latter is the case, the filled array should
            be broadcastable over input array. Default is None, in
            which case the `fill_value` attribute is used instead.

        Returns
        -------
        filled_void
            A `np.void` object

        See Also
        --------
        MaskedArray.filled

        r�)r0rN)r}rMs  r�rNzmvoid.filleds#��,�t�}�}�#�#�J�/�/��3�3r�c�4�|j}|tur|j���Sg}t	|j|j��D]D\}}|r|�d���|�|������Et|��S)z�
    Transforms the mvoid object into a tuple.

    Masked fields are replaced by None.

    Returns
    -------
    returned_tuple
        Tuple of fields
        N)rqr�rjrr=r"r?r)r}rqrUr�r�s     r�rzmvoid.tolist3s����
���F�?�?��:�$�$�&�&�&����$�*�d�j�1�1�	(�	(�F�Q���
(��
�
�d�#�#�#�#��
�
�a�f�f�h�h�'�'�'�'��V�}�}�r�r)r�r�r�r�r�r�r6rjr�r�r�r[rrJrNrr�r�s@r�r�r��s����������"(�t���U�$�����(�!�!�!�!��X�!� � � �,>�>�>�	�	�	�	�	��H�
�
�
�$�$�$�4�4�4�4�0������r�r�c�,�t|t��S)a�
    Test whether input is an instance of MaskedArray.

    This function returns True if `x` is an instance of MaskedArray
    and returns False otherwise.  Any object is accepted as input.

    Parameters
    ----------
    x : object
        Object to test.

    Returns
    -------
    result : bool
        True if `x` is a MaskedArray.

    See Also
    --------
    isMA : Alias to isMaskedArray.
    isarray : Alias to isMaskedArray.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.eye(3, 3)
    >>> a
    array([[ 1.,  0.,  0.],
           [ 0.,  1.,  0.],
           [ 0.,  0.,  1.]])
    >>> m = ma.masked_values(a, 0)
    >>> m
    masked_array(
      data=[[1.0, --, --],
            [--, 1.0, --],
            [--, --, 1.0]],
      mask=[[False,  True,  True],
            [ True, False,  True],
            [ True,  True, False]],
      fill_value=0.0)
    >>> ma.isMaskedArray(a)
    False
    >>> ma.isMaskedArray(m)
    True
    >>> ma.isMaskedArray([0, 1, 2])
    False

    )r!r�r�s r�rerePs��`�a��%�%�%r�c���eZdZdZed���Zd�Z�fd�Zdd�Zdd�Z	d�Z
d�Zd	�Zd
�Z
d�ZexZxZxZxZxZZ[d�Zd
�Zd�Z�fd�Z�xZS)r`Nc�@�|jduot|j��|uSr)�_MaskedConstant__singletonr^)res r��__has_singletonzMaskedConstant.__has_singleton�s%����d�*�K�t�C�O�/D�/D��/K�Kr�c�
�|���sitjd��}tjd��}d|j_d|j_t||����|��|_|jS)Nr�TFr�)�_MaskedConstant__has_singletonrrr��	writeablerrlrQ)rermros   r�r�zMaskedConstant.__new__�su���"�"�$�$�
	E��8�B�<�<�D��8�D�>�>�D�$)�D�J� �#(�D�J� �
*�$�T�:�:�:�?�?��D�D�C�O���r�c����|���s!t���|��S||jurdSt|_t�||��dSr)rTr�r�rQrr�)r}r�r�s  �r�r�z!MaskedConstant.__array_finalize__�si����#�#�%�%�	6��7�7�-�-�c�2�2�2�
�T�%�
%�
%��D�)�D�N��*�*�4��5�5�5�5�5r�c�^�|�t���||��Sr)rlr�__array_prepare__�r}r�r�s   r�rXz MaskedConstant.__array_prepare__�s$���y�y��%�%�7�7��W�E�E�Er�c�^�|�t���||��Sr)rlrr�rYs   r�r�zMaskedConstant.__array_wrap__�s$���y�y��%�%�4�4�S�'�B�B�Br�c�4�ttj��Sr)r+r�rMr�s r�r�zMaskedConstant.__str__�s���&�/�0�0�0r�c�V�|tjurdSt�|��S)Nrw)r`rQrJr[r�s r�r[zMaskedConstant.__repr__�s)���>�-�-�-��8��?�?�4�(�(�(r�c���	t�||��S#t$r:tjdt
d���t�|d��cYSwxYw)NzjFormat strings passed to MaskedConstant are ignored, but in future may error or produce different behaviorr�r�r�)rJ�
__format__r�r�r��
FutureWarning)r}�format_specs  r�r^zMaskedConstant.__format__�sy��		/��$�$�T�;�7�7�7���	/�	/�	/��M�6��!�
�
�
�
�
�$�$�T�2�.�.�.�.�.�	/���s��AA!� A!c��|jdfS)z.Override of MaskedArray's __reduce__.
        r�r�r�s r�rzMaskedConstant.__reduce__�s�����#�#r�c��|Srr�rRs  r��__iop__zMaskedConstant.__iop__�r�r�c��|S)z: Copy is a no-op on the maskedconstant, as it is a scalar r�)r}r�r�s   r�r=zMaskedConstant.copy�s	���r�c��|Srr�r�s r��__copy__zMaskedConstant.__copy__�r�r�c��|Srr�)r}r*s  r�r-zMaskedConstant.__deepcopy__�r�r�c����|���s"t���||��S||jurt	d|�d����t���||��S)Nzattributes of z are not writeable)rTr��__setattr__rQrk)r}�attrr-r�s   �r�rizMaskedConstant.__setattr__�s{����#�#�%�%�		4��7�7�&�&�t�U�3�3�3�
�T�%�
%�
%� �;��;�;�;�=�=�
=�
�7�7�&�&�t�U�3�3�3r�r)r�r�r�rQ�classmethodrTr�r�rXr�r�r[r^rrcr�r�r�r�r�r�r=rfr-rir�r�s@r�r`r`�s_��������K��L�L��[�L�
���$6�6�6�6�6�F�F�F�F�C�C�C�C�1�1�1�)�)�)�
/�
/�
/�$�$�$����	�
�H��������������������
4�
4�
4�
4�
4�
4�
4�
4�
4r�r`c
�6�t|||||	||||
||���S)z~
    Shortcut to MaskedArray.

    The options are in a different order for convenience and backwards
    compatibility.

    )
rorr=rir�r�rMr�rr�)r)rmrr=r�rorMr�r�rrir�s           r�rr�s8���t�$�e�$�"�i�!*�z�"�6��@�@�@�@r�c�f�t|��}|turdS|���rdSdS)a
    Determine whether input has masked values.

    Accepts any object as input, but always returns False unless the
    input is a MaskedArray containing masked values.

    Parameters
    ----------
    x : array_like
        Array to check for masked values.

    Returns
    -------
    result : bool
        True if `x` is a MaskedArray with masked values, False otherwise.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> x = ma.masked_equal([0, 1, 0, 2, 3], 0)
    >>> x
    masked_array(data=[--, 1, --, 2, 3],
                 mask=[ True, False,  True, False, False],
           fill_value=0)
    >>> ma.is_masked(x)
    True
    >>> x = ma.masked_equal([0, 1, 0, 2, 3], 42)
    >>> x
    masked_array(data=[0, 1, 0, 2, 3],
                 mask=False,
           fill_value=42)
    >>> ma.is_masked(x)
    False

    Always returns False if `x` isn't a MaskedArray.

    >>> x = [False, True, False]
    >>> ma.is_masked(x)
    False
    >>> x = 'a string'
    >>> ma.is_masked(x)
    False

    FT)rYr�r!)r�r�s  r�rgrgs8��Z	��
�
�A��F�{�{��u�	
�������t��5r�c�B��eZdZdZ�fd�Zd�Zejfd�Zd�Z	�xZ
S)�_extrema_operationz�
    Generic class for maximum/minimum functions.

    .. note::
      This is the base class for `_maximum_operation` and
      `_minimum_operation`.

    c�f��t���|��||_||_dSr)r�r~rH�fill_value_func)r}r�rHrMr�s    �r�r~z_extrema_operation.__init__Ss0���
������������)����r�c�L�t|�||��||��S)r�)r�rHr|s   r�r�z_extrema_operation.__call__Xs$���T�\�\�!�Q�'�'��A�.�.�.r�c��t|dd���}t|��}|tjur:|jdkr/tjd|j�d|j�d�td�	��d
}|tjurt|���}nt��}|tur|jj|fi|��}n�|�
|�|�����t!|����}|jj|fi|��}t#jj|fi|��}t'|d��r||_n	|rt*}|S)
z#Reduce target along the given axis.FTrhr�z!In the future the default for ma.z:.reduce will be axis=0, not the current None, to match np.z;.reduce. Explicitly pass 0 or None to silence this warning.r�r�Nr�rq)rrYrr
r�r�r�r�r�r[r�r�rrNrqrlr^r�ror"rqrw)r}r�r�r�r�r�s      r�rz_extrema_operation.reduce]st����U�$�7�7�7���F�O�O���2�;���6�;��?�?��M�E�D�M�E�E�59�]�E�E�E�)�Q�	
8�
8�
8�
8�
�D��r�{�"�"��t�_�_�_�F�F��V�V�F���;�;����
�f�/�/��/�/�A�A��]�]��$�$�V�,�,�.�.�.2�d�4��<�<�.@�.@�
����
�f�/�/��/�/�A��!�(��5�5�f�5�5�A��q�'�"�"�
������
����r�c��t|��}t|��}|tur|turt}n9t|��}t|��}t�||��}|j�t
|��t
|����}t|t��s|�	t��}||_
|S)z<Return the function applied to the outer product of a and b.)rYr�rZrqr�r�rNr!rrlrq)r}rSr�r�r�r�rUs       r�r�z_extrema_operation.outer}s���
�Q�Z�Z��
�Q�Z�Z��
��<�<�B�&�L�L��A�A��a���B��a���B�� � ��R�(�(�A�����f�Q�i�i�����3�3���&�+�.�.�	.��[�[��-�-�F�����
r�)r�r�r�r�r~r�rr
rr�r�r�s@r�roroJs|���������*�*�*�*�*�
/�/�/�
#%�+�����@������r�roc��|tjurind|i}	|jd|||d�|��S#ttf$r!t|��jd|||d�|��cYSwxYw�Nr!�r�rMrtr�)rr
r�rkr�r/�r�r�rtrMr!r�s      r�r�r������r�{�*�*�R�R��X�0F�F�6��s�w�K�D�Z�S�K�K�F�K�K�K���I�&�6�6�6�#�z�#���"�6���'*�6�6�.4�6�6�	6�	6�	6�6�����'�/A�Ac��|tjurind|i}	|jd|||d�|��S#ttf$r!t|��jd|||d�|��cYSwxYwrv)rr
r�rkr�r/rxs      r�r�r��ryrzc��|tjurind|i}	|j|f||d�|��S#ttf$r!t|��jd|||d�|��cYSwxYw)Nr!)rtrMrwr�)rr
r�rkr�r/rxs      r�r�r��s����r�{�*�*�R�R��X�0F�F�6��s�w�t�F���F�F�v�F�F�F���I�&�6�6�6�#�z�#���"�6���'*�6�6�.4�6�6�	6�	6�	6�6���rzc�&�eZdZdZdd�Zd�Zd�ZdS)�_frommethodz�
    Define functions from existing MaskedArray methods.

    Parameters
    ----------
    methodname : str
        Name of the method to transform.

    Fc�T�||_|���|_||_dSr)r��getdocr��reversed)r}�
methodnamer�s   r�r~z_frommethod.__init__�s#��"��
��{�{�}�}��� ��
�
�
r�c���tt|jd��ptt|jd��}|jt	|��z}|�d|�dt|dd����}|SdS)�<Return the doc of the function (from the doc of the method).Nz    r"r�)r�rr�rr�)r}�meth�	signature�docs    r�r�z_frommethod.getdoc�sx���{�D�M�4�8�8�-��B��
�t�,�,�	
��M�$8��$>�$>�>�	�����	�	�7�4��D�9�9�9�;�C��J��r�c��|jrt|��}|d|c}|d<t|��}|j}t	t|��|d��}|�t	t|��}||g|�Ri|��Sr�)r�rur/r�r�r^r)r}rSr�rx�marr�method_name�methods       r�r�z_frommethod.__call__�s����=�	$���:�:�D��a��!�J�A�t�A�w��!�}�}���m����d���[�$�7�7���>��R��-�-�F��v�d�,�T�,�,�,�V�,�,�,r�Nr.)r�r�r�r�r~r�r�r�r�r�r~r~�sP��������!�!�!�!�
���-�-�-�-�-r�r~rrr!r8)r�rBrCr=rFr]r`r�r�r�r�r�rEr�r�r�r�r�r�rAr�c�R�t|��}|�||||���S)z
    )r�rtr�)rxr�)rSrar�rtr�s     r�r�r��s)��	�Q���A��6�6�'��#�D�6�9�9�9r�c	��|�td���t|��}t|��}t||��}t|��}t|��}t	|t
��rt
|��}nt
}tjdd���5tj	||tj||�����|��}	ddd��n#1swxYwY|	�
|��tjtj|	�t ������}
|t"ur(|	jst&Stj||
��|	_|
���r2|	jst&S|	jt"ur|
|	_|	j|	j|
<|	S)a�
    Returns element-wise base array raised to power from second array.

    This is the masked array version of `numpy.power`. For details see
    `numpy.power`.

    See Also
    --------
    numpy.power

    Notes
    -----
    The *out* argument to `numpy.power` is not supported, `third` has to be
    None.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> x = [11.2, -3.973, 0.801, -1.41]
    >>> mask = [0, 0, 0, 1]
    >>> masked_x = ma.masked_array(x, mask)
    >>> masked_x
    masked_array(data=[11.2, -3.973, 0.801, --],
             mask=[False, False, False,  True],
       fill_value=1e+20)
    >>> ma.power(masked_x, 2)
    masked_array(data=[125.43999999999998, 15.784728999999999,
                   0.6416010000000001, --],
             mask=[False, False, False,  True],
       fill_value=1e+20)
    >>> y = [-0.5, 2, 0, 17]
    >>> masked_y = ma.masked_array(y, mask)
    >>> masked_y
    masked_array(data=[-0.5, 2.0, 0.0, --],
             mask=[False, False, False,  True],
       fill_value=1e+20)
    >>> ma.power(masked_x, masked_y)
    masked_array(data=[0.29880715233359845, 15.784728999999999, 1.0, --],
             mask=[False, False, False,  True],
       fill_value=1e+20)

    Nz3-argument power not supported.r�r�)rrYrvrXr!rr^rr�r�r�r�rlr�rprprr�r�rwrqrqr!rMrj)rSr��thirdr�r�r��fa�fbr@rUrrs           r�r�r�s���V
���9�:�:�:�	����B�	����B���B���A�	����B�	����B��!�[�!�!����7�7�����	��H�h�	7�	7�	7�E�E���!�R���R��!4�!4�5�5�:�:�8�D�D��E�E�E�E�E�E�E�E�E�E�E����E�E�E�E�
��������n�R�[����W�)=�)=�>�>�?�?�G������{�	��M��}�Q��0�0����{�{�}�}�2��{�	#��M�
�\�V�
#�
#�"�F�L� &� 1���W���Ms� =C)�)C-�0C-r,r+c���tj|��}|tjurt|��}t	|t
��r|�|||||���S|�|||���S)z)Function version of the eponymous method.�r�r(r�r�rMr�)rr/r
r�r!rr-�rSr�r(r�r�rMs      r�r-r-Ts���
�
�a���A��r�{���&�q�)�)���!�[�!�!�<��y�y�d��U�!(�Z��A�A�	A��y�y�d��U�y�;�;�;r�r�c���tj|dd���}|�|���}d}t|t��r|�|||||���n|�|||���|S)a�
    Return a sorted copy of the masked array.

    Equivalent to creating a copy of the array
    and applying the  MaskedArray ``sort()`` method.

    Refer to ``MaskedArray.sort`` for the full documentation

    See Also
    --------
    MaskedArray.sort : equivalent method

    Examples
    --------
    >>> import numpy.ma as ma
    >>> x = [11.2, -3.973, 0.801, -1.41]
    >>> mask = [0, 0, 0, 1]
    >>> masked_x = ma.masked_array(x, mask)
    >>> masked_x
    masked_array(data=[11.2, -3.973, 0.801, --],
                 mask=[False, False, False,  True],
           fill_value=1e+20)
    >>> ma.sort(masked_x)
    masked_array(data=[-3.973, 0.801, 11.2, --],
                 mask=[False, False, False,  True],
           fill_value=1e+20)
    TrhNrr�r�)rrrr!rr�r�s      r�r�r�cs���8	����T�*�*�*�A��|�
�I�I�K�K�����!�[�!�!�2�	���D�t�5��:�	�	7�	7�	7�	7�	
���D�t�5��1�1�1��Hr�c�D�t|�����S)ag
    Return all the non-masked data as a 1-D array.

    This function is equivalent to calling the "compressed" method of a
    `ma.MaskedArray`, see `ma.MaskedArray.compressed` for details.

    See Also
    --------
    ma.MaskedArray.compressed : Equivalent method.

    Examples
    --------
    
    Create an array with negative values masked:

    >>> import numpy as np
    >>> x = np.array([[1, -1, 0], [2, -1, 3], [7, 4, -1]])
    >>> masked_x = np.ma.masked_array(x, mask=x < 0)
    >>> masked_x
    masked_array(
      data=[[1, --, 0],
            [2, --, 3],
            [7, 4, --]],
      mask=[[False,  True, False],
            [False,  True, False],
            [False, False,  True]],
      fill_value=999999)

    Compress the masked array into a 1-D array of non-masked values:

    >>> np.ma.compressed(masked_x)
    array([1, 0, 2, 3, 7, 4])

    )r/r9rNs r�r9r9�s��F�a�=�=�#�#�%�%�%r�c�X�tjd�|D��|��}t|�}|�|��}|D]}t	|��t
urn�|Stjd�|D��|��}|�|j��}t|��|_	|S)aI
    Concatenate a sequence of arrays along the given axis.

    Parameters
    ----------
    arrays : sequence of array_like
        The arrays must have the same shape, except in the dimension
        corresponding to `axis` (the first, by default).
    axis : int, optional
        The axis along which the arrays will be joined. Default is 0.

    Returns
    -------
    result : MaskedArray
        The concatenated array with any masked entries preserved.

    See Also
    --------
    numpy.concatenate : Equivalent function in the top-level NumPy module.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = ma.arange(3)
    >>> a[1] = ma.masked
    >>> b = ma.arange(2, 5)
    >>> a
    masked_array(data=[0, --, 2],
                 mask=[False,  True, False],
           fill_value=999999)
    >>> b
    masked_array(data=[2, 3, 4],
                 mask=False,
           fill_value=999999)
    >>> ma.concatenate([a, b])
    masked_array(data=[0, --, 2, 2, 3, 4],
                 mask=[False,  True, False, False, False, False],
           fill_value=999999)

    c�,�g|]}t|����Sr�)rXr_s  r�rzconcatenate.<locals>.<listcomp>�s��3�3�3�q���
�
�3�3�3r�c�,�g|]}t|����Sr�r�r_s  r�rzconcatenate.<locals>.<listcomp>�s��9�9�9�Q��a���9�9�9r�)
rr:rfrlrYr�r�r�r�rq)rbr�r�rcrmr��dms       r�r:r:�s���R	��3�3�F�3�3�3�T�:�:�A���'�D��6�6�$�<�<�D�
�����1�:�:�V�#�#��E�$���	��9�9�&�9�9�9�4�	@�	@�B�	���A�G�	�	�B��b�!�!�D�J��Kr�c���tj||���t��}t	|��t
urtj|j|��|_|S)az
    Extract a diagonal or construct a diagonal array.

    This function is the equivalent of `numpy.diag` that takes masked
    values into account, see `numpy.diag` for details.

    See Also
    --------
    numpy.diag : Equivalent function for ndarrays.

    Examples
    --------

    Create an array with negative values masked:

    >>> import numpy as np
    >>> x = np.array([[11.2, -3.973, 18], [0.801, -1.41, 12], [7, 33, -12]])
    >>> masked_x = np.ma.masked_array(x, mask=x < 0)
    >>> masked_x
    masked_array(
      data=[[11.2, --, 18.0],
            [0.801, --, 12.0],
            [7.0, 33.0, --]],
      mask=[[False,  True, False],
            [False,  True, False],
            [False, False,  True]],
      fill_value=1e+20)

    Isolate the main diagonal from the masked array:

    >>> np.ma.diag(masked_x)
    masked_array(data=[11.2, --, --],
                 mask=[False,  True,  True],
           fill_value=1e+20)

    Isolate the first diagonal below the main diagonal:

    >>> np.ma.diag(masked_x, -1)
    masked_array(data=[0.801, 33.0],
                 mask=[False, False],
           fill_value=1e+20)

    )rrErlrrYr�rq)r,rr3s   r�rErE�sM��X�W�Q��]�]�
�
��
,�
,�F��q�z�z�����w�q�w��*�*����Mr�c��t|��}|tur1tjt	|��|��}t|��Stjt	|d��|��}t||���S)z�
    Shift the bits of an integer to the left.

    This is the masked array version of `numpy.left_shift`, for details
    see that function.

    See Also
    --------
    numpy.left_shift

    rr�)rYr�r�rirNrx�rSr�r�r�s    r�riri si��	��
�
�A��F�{�{���V�A�Y�Y��*�*���A������V�A�q�\�\�1�-�-���A�A�&�&�&�&r�c��t|��}|tur1tjt	|��|��}t|��Stjt	|d��|��}t||���S)a�
    Shift the bits of an integer to the right.

    This is the masked array version of `numpy.right_shift`, for details
    see that function.

    See Also
    --------
    numpy.right_shift

    Examples
    --------
    >>> import numpy.ma as ma
    >>> x = [11, 3, 8, 1]
    >>> mask = [0, 0, 0, 1]
    >>> masked_x = ma.masked_array(x, mask)
    >>> masked_x
    masked_array(data=[11, 3, 8, --],
                 mask=[False, False, False,  True],
           fill_value=999999)
    >>> ma.right_shift(masked_x,1)
    masked_array(data=[5, 1, 4, --],
                 mask=[False, False, False,  True],
           fill_value=999999)

    rr�)rYr�r�r�rNrxr�s    r�r�r�5si��6	��
�
�A��F�{�{���f�Q�i�i��+�+���A������f�Q��l�l�A�.�.���A�A�&�&�&�&r�c��	|�|||���S#t$r*t|d����|||���cYSwxYw)z�
    Set storage-indexed locations to corresponding values.

    This function is equivalent to `MaskedArray.put`, see that method
    for details.

    See Also
    --------
    MaskedArray.put

    r�Fr�)r�rkr)rSrar�r�s    r�r�r�Ysm��E��u�u�W�f�4�u�0�0�0���E�E�E��a�e�$�$�$�(�(��&�t�(�D�D�D�D�D�E���s��1A�
Ac��t|t��s|�t��}t|��t	|��}}t	|��t
urL|t
urBd|_t|j|j	��|_
tj|j
||���n�|j
rJ|t
ur@|j
���}tj|||���|xj|zc_n4|t
urt!|��}tj|j
||���tj|j||���dS)aQ
    Changes elements of an array based on conditional and input values.

    This is the masked array version of `numpy.putmask`, for details see
    `numpy.putmask`.

    See Also
    --------
    numpy.putmask

    Notes
    -----
    Using a masked array as `values` will **not** transform a `ndarray` into
    a `MaskedArray`.

    Tr�N)r!rrlrXrYr�r�rur�rrqrr�r�r=rorZrj)rSror��valdata�valmaskr�s      r�r�r�ls(��$�a��%�%� �
�F�F�;����!�&�/�/�7�6�?�?�g�W��q�z�z�V����&� � � �A�M�$�Q�W�a�g�6�6�A�G��I�a�g�w�d�3�3�3�3��	
��0��&� � �������A��I�a���-�-�-�-�
�F�F�a�K�F�F���f���"�6�*�*�G�
�	�!�'�7�$�/�/�/�/��I�a�g�w�d�+�+�+�+�
�Fr�c���	|�|��S#t$r?t|d����|���t��cYSwxYw)a�
    Permute the dimensions of an array.

    This function is exactly equivalent to `numpy.transpose`.

    See Also
    --------
    numpy.transpose : Equivalent function in top-level NumPy module.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> x = ma.arange(4).reshape((2,2))
    >>> x[1, 1] = ma.masked
    >>> x
    masked_array(
      data=[[0, 1],
            [2, --]],
      mask=[[False, False],
            [False,  True]],
      fill_value=999999)

    >>> ma.transpose(x)
    masked_array(
      data=[[0, 2],
            [1, --]],
      mask=[[False, False],
            [False,  True]],
      fill_value=999999)
    Fr�)r�rkrrlr)rSr�s  r�r�r��so��@G��{�{�4� � � ���G�G�G��a�e�$�$�$�.�.�t�4�4�9�9�+�F�F�F�F�F�G���s��AA �A r�c���	|�||���S#t$rCt|d����||���}|�t��cYSwxYw)z�
    Returns an array containing the same data with a new shape.

    Refer to `MaskedArray.reshape` for full documentation.

    See Also
    --------
    MaskedArray.reshape : equivalent function

    r�Fr�)r�rkrrlr)rS�	new_shaper��_tmps    r�r�r��su��&��y�y��%�y�0�0�0���&�&�&��a�e�$�$�$�,�,�Y�e�,�D�D���y�y��%�%�%�%�%�&���s��A
A&�%A&c���t|��}|turtj||��}tj||���t|����}|jr||_|S)a
    Return a new masked array with the specified size and shape.

    This is the masked equivalent of the `numpy.resize` function. The new
    array is filled with repeated copies of `x` (in the order that the
    data are stored in memory). If `x` is masked, the new array will be
    masked, and the new mask will be a repetition of the old one.

    See Also
    --------
    numpy.resize : Equivalent function in the top level NumPy module.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = ma.array([[1, 2] ,[3, 4]])
    >>> a[0, 1] = ma.masked
    >>> a
    masked_array(
      data=[[1, --],
            [3, 4]],
      mask=[[False,  True],
            [False, False]],
      fill_value=999999)
    >>> np.resize(a, (3, 3))
    masked_array(
      data=[[1, 2, 3],
            [4, 1, 2],
            [3, 4, 1]],
      mask=False,
      fill_value=999999)
    >>> ma.resize(a, (3, 3))
    masked_array(
      data=[[1, --, 3],
            [4, 1, --],
            [3, 4, 1]],
      mask=[[False,  True, False],
            [False, False,  True],
            [False, False, False]],
      fill_value=999999)

    A MaskedArray is always returned, regardless of the input type.

    >>> a = np.array([[1, 2] ,[3, 4]])
    >>> ma.resize(a, (3, 3))
    masked_array(
      data=[[1, 2, 3],
            [4, 1, 2],
            [3, 4, 1]],
      mask=False,
      fill_value=999999)

    )rYr�rr�rlrfr�rq)r�r�r�rUs    r�r�r��sh��n	��
�
�A������I�a��#�#��
�Y�q�)�
$�
$�
)�
)�*=�a�*@�*@�
A�
A�F�
�{������Mr�c�D�tjt|����S)z5
    maskedarray version of the numpy function.

    )rr�rXr#s r�r�r�s��
�7�7�3�<�<� � � r�c�D�tjt|����S��*maskedarray version of the numpy function.)rr�rXr#s r�r�r�s��
�8�G�C�L�L�!�!�!r�c�F�tjt|��|��Sr�)rr�rX)r�r�s  r�r�r�s��
�7�7�3�<�<��&�&�&r�c��|dkr|S|dkrtdt|��z���tj�|��}|jdkrtd���g}|tjurztj�|��}|jdkr;t|j��}d||<tj	|t|����}|�|��|�|��|tjurztj�|��}|jdkr;t|j��}d||<tj	|t|����}|�|��t|��dkr tj�
||��}tj|||��S)a�
    Calculate the n-th discrete difference along the given axis.
    The first difference is given by ``out[i] = a[i+1] - a[i]`` along
    the given axis, higher differences are calculated by using `diff`
    recursively.
    Preserves the input mask.

    Parameters
    ----------
    a : array_like
        Input array
    n : int, optional
        The number of times values are differenced. If zero, the input
        is returned as-is.
    axis : int, optional
        The axis along which the difference is taken, default is the
        last axis.
    prepend, append : array_like, optional
        Values to prepend or append to `a` along axis prior to
        performing the difference.  Scalar values are expanded to
        arrays with length 1 in the direction of axis and the shape
        of the input array in along all other axes.  Otherwise the
        dimension and shape must match `a` except along axis.

    Returns
    -------
    diff : MaskedArray
        The n-th differences. The shape of the output is the same as `a`
        except along `axis` where the dimension is smaller by `n`. The
        type of the output is the same as the type of the difference
        between any two elements of `a`. This is the same as the type of
        `a` in most cases. A notable exception is `datetime64`, which
        results in a `timedelta64` output array.

    See Also
    --------
    numpy.diff : Equivalent function in the top-level NumPy module.

    Notes
    -----
    Type is preserved for boolean arrays, so the result will contain
    `False` when consecutive elements are the same and `True` when they
    differ.

    For unsigned integer arrays, the results will also be unsigned. This
    should not be surprising, as the result is consistent with
    calculating the difference directly:

    >>> u8_arr = np.array([1, 0], dtype=np.uint8)
    >>> np.ma.diff(u8_arr)
    masked_array(data=[255],
                 mask=False,
           fill_value=999999,
                dtype=uint8)
    >>> u8_arr[1,...] - u8_arr[0,...]
    255

    If this is not desirable, then the array should be cast to a larger
    integer type first:

    >>> i16_arr = u8_arr.astype(np.int16)
    >>> np.ma.diff(i16_arr)
    masked_array(data=[-1],
                 mask=False,
           fill_value=999999,
                dtype=int16)

    Examples
    --------
    >>> a = np.array([1, 2, 3, 4, 7, 0, 2, 3])
    >>> x = np.ma.masked_where(a < 2, a)
    >>> np.ma.diff(x)
    masked_array(data=[--, 1, 1, 3, --, --, 1],
            mask=[ True, False, False, False,  True,  True, False],
        fill_value=999999)

    >>> np.ma.diff(x, n=2)
    masked_array(data=[--, 0, 2, --, --, --],
                mask=[ True, False, False,  True,  True,  True],
        fill_value=999999)

    >>> a = np.array([[1, 3, 1, 5, 10], [0, 1, 5, 6, 8]])
    >>> x = np.ma.masked_equal(a, value=1)
    >>> np.ma.diff(x)
    masked_array(
        data=[[--, --, --, 5],
                [--, --, 1, 2]],
        mask=[[ True,  True,  True, False],
                [ True,  True, False, False]],
        fill_value=1)

    >>> np.ma.diff(x, axis=0)
    masked_array(data=[[--, --, --, 1, -2]],
            mask=[[ True,  True,  True, False, False]],
        fill_value=1)

    rz#order must be non-negative but got z4diff requires input that is at least one dimensionalr�)rIr1rr�r/r�r
rur�rGrr"r<r:rG)rSr�r��prependr"�combinedr�s       r�rGrG"s���D	�A�v�v����1�u�u��>��a���H�I�I�I�
�������A��v��{�{��B���	��H��b�k�!�!��%�"�"�7�+�+���<�1������M�M�E��E�$�K��o�g�u�U�|�|�<�<�G����� � � ��O�O�A����
�R�[� � ���!�!�&�)�)���;�!������M�M�E��E�$�K��_�V�U�5�\�\�:�:�F��������
�8�}�}�q����E���h��-�-���7�1�a����r�c�n�|tu|tuf�d��}|dkrtd���|dkrt|��St	|d��}t|��}t|��}t
|��}t
|��}t
|��}	|tur@|tur7tj	d|j
���}tjd|	j
���}nH|tur?|tur6tj	d|j
���}tjd|j
���}	tj|||��}
tj|||	��}tj|tjd|j
���|��}t|��}t|
|���S)	a�
    Return a masked array with elements from `x` or `y`, depending on condition.

    .. note::
        When only `condition` is provided, this function is identical to
        `nonzero`. The rest of this documentation covers only the case where
        all three arguments are provided.

    Parameters
    ----------
    condition : array_like, bool
        Where True, yield `x`, otherwise yield `y`.
    x, y : array_like, optional
        Values from which to choose. `x`, `y` and `condition` need to be
        broadcastable to some shape.

    Returns
    -------
    out : MaskedArray
        An masked array with `masked` elements where the condition is masked,
        elements from `x` where `condition` is True, and elements from `y`
        elsewhere.

    See Also
    --------
    numpy.where : Equivalent function in the top-level NumPy module.
    nonzero : The function that is called when x and y are omitted

    Examples
    --------
    >>> x = np.ma.array(np.arange(9.).reshape(3, 3), mask=[[0, 1, 0],
    ...                                                    [1, 0, 1],
    ...                                                    [0, 1, 0]])
    >>> x
    masked_array(
      data=[[0.0, --, 2.0],
            [--, 4.0, --],
            [6.0, --, 8.0]],
      mask=[[False,  True, False],
            [ True, False,  True],
            [False,  True, False]],
      fill_value=1e+20)
    >>> np.ma.where(x > 5, x, -3.1416)
    masked_array(
      data=[[-3.1416, --, -3.1416],
            [--, -3.1416, --],
            [6.0, --, 8.0]],
      mask=[[False,  True, False],
            [ True, False,  True],
            [False,  True, False]],
      fill_value=1e+20)

    Tr�z)Must provide both 'x' and 'y' or neither.r�Fr�rr�)r
rArIr�rNrXrZrwrr�rr�r�r�rx)r'r�r�missingr�xd�yd�cm�xm�ymrmros            r�r�r��s���p�H�}�a�8�m�,�2�2�4�8�8�G��!�|�|��D�E�E�E��!�|�|��y�!�!�!�
�	�5�	!�	!�B�	����B�	����B�
�i�	 �	 �B�	�a���B�	�a���B�	�F�{�{�q����
�X�b���
)�
)�
)��
�W�R���
)�
)�
)���	
�f����&���
�X�b���
)�
)�
)��
�W�R���
)�
)�
)��
�8�B��B���D�
�8�B��B���D�
�8�B����$�*�5�5�5�t�<�<�D�����D���4�(�(�(�(r�c���	�
�d��	d��
t|d��}�
fd�|D��}�	fd�|D��}tj|||���}tt	|t|����dd�	��}tj||||�
���t��}|�,t|t��r|�	|��|S|�	|��|S)aH
    Use an index array to construct a new array from a list of choices.

    Given an array of integers and a list of n choice arrays, this method
    will create a new array that merges each of the choice arrays.  Where a
    value in `index` is i, the new array will have the value that choices[i]
    contains in the same place.

    Parameters
    ----------
    indices : ndarray of ints
        This array must contain integers in ``[0, n-1]``, where n is the
        number of choices.
    choices : sequence of arrays
        Choice arrays. The index array and all of the choices should be
        broadcastable to the same shape.
    out : array, optional
        If provided, the result will be inserted into this array. It should
        be of the appropriate shape and `dtype`.
    mode : {'raise', 'wrap', 'clip'}, optional
        Specifies how out-of-bounds indices will behave.

        * 'raise' : raise an error
        * 'wrap' : wrap around
        * 'clip' : clip to the range

    Returns
    -------
    merged_array : array

    See Also
    --------
    choose : equivalent function

    Examples
    --------
    >>> choice = np.array([[1,1,1], [2,2,2], [3,3,3]])
    >>> a = np.array([2, 1, 0])
    >>> np.ma.choose(a, choice)
    masked_array(data=[3, 2, 1],
                 mask=False,
           fill_value=999999)

    c�6�|turdSt|��S)z,Returns the filled array, or True if masked.T)rwrNrNs r��fmaskzchoose.<locals>.fmask6s����;�;��4��a�y�y�r�c�6�|turdSt|��S)z:Returns the mask, True if ``masked``, False if ``nomask``.T)rwrYrNs r��nmaskzchoose.<locals>.nmask<s����;�;��4��q�z�z�r�rc�&��g|]
}�|����Sr�r�)rr�r�s  �r�rzchoose.<locals>.<listcomp>Ds!���'�'�'�!�U�U�1�X�X�'�'�'r�c�&��g|]
}�|����Sr�r�)rr�r�s  �r�rzchoose.<locals>.<listcomp>Es!���&�&�&��E�E�!�H�H�&�&�&r�r�FTr)r�rt)
rNrr5rsrvrYrlrr!rw)ra�choicesrtr�r��masksrm�
outputmaskr�r�r�s         @@r�r5r5	s����Z������	�w����A�'�'�'�'�w�'�'�'�E�&�&�&�&�g�&�&�&�D���1�e�$�/�/�/�J��7�:�w�w�/?�/?�@�@� %�d�4�4�4�J�	�	�!�T��#�.�.�.�3�3�K�@�@�A�
���c�;�'�'�	(��O�O�J�'�'�'��
��M�M�*�����Hr�c���|�tj|||��Stjt|��||��t|d��rt	|��|_|S)a�
    Return a copy of a, rounded to 'decimals' places.

    When 'decimals' is negative, it specifies the number of positions
    to the left of the decimal point.  The real and imaginary parts of
    complex numbers are rounded separately. Nothing is done if the
    array is not of float type and 'decimals' is greater than or equal
    to 0.

    Parameters
    ----------
    decimals : int
        Number of decimals to round to. May be negative.
    out : array_like
        Existing array to use for output.
        If not given, returns a default copy of a.

    Notes
    -----
    If out is given and does not have a mask attribute, the mask of a
    is lost!

    Examples
    --------
    >>> import numpy.ma as ma
    >>> x = [11.2, -3.973, 0.801, -1.41]
    >>> mask = [0, 0, 0, 1]
    >>> masked_x = ma.masked_array(x, mask)
    >>> masked_x
    masked_array(data=[11.2, -3.973, 0.801, --],
                 mask=[False, False, False, True],
        fill_value=1e+20)
    >>> ma.round_(masked_x)
    masked_array(data=[11.0, -4.0, 1.0, --],
                 mask=[False, False, False, True],
        fill_value=1e+20)
    >>> ma.round(masked_x, decimals=1)
    masked_array(data=[11.2, -4.0, 0.8, --],
                 mask=[False, False, False, True],
        fill_value=1e+20)
    >>> ma.round_(masked_x, decimals=-1)
    masked_array(data=[10.0, -0.0, 0.0, --],
                 mask=[False, False, False, True],
        fill_value=1e+20)
    Nrq)rr�rXr"rYrq)rSr�rts   r�r�r�Ts\��\�{��y��H�c�*�*�*�
�	�'�!�*�*�h��,�,�,��3�� � �	#���
�
�C�I��
r�c�B�t|d���}t|��}|tus|���r|�|S|j���|_t
||j��}|D]'}|xj|�|d���zc_�(|S)zH
    Mask whole 1-d vectors of an array that contain masked values.
    FrBNT)r�r!)rrYr�r!rqr=rr�)rSr�r�r�r�s     r��_mask_propagater��s���	�a�u����A���
�
�A��F�{�{�!�%�%�'�'�{�T�\����g�l�l�n�n�A�G���a�f�-�-�D��1�1��	���1�5�5�b�4�5�0�0�0�����Hr�c�:�|dur�tj|��dkstj|��dkrnl|jdkr1t||jdz
��}t||jdz
��}n0t||jdz
��}t||jdz
��}t|��}t|��}|��tjt|d��t|d����}tj||��}tj|��dkrtj|��}|�t||����}|�	|��|Stjt|d��t|d��|j
��}|jj|jkr$tj
|jt��|_tj|||j��tj|j|j��|S)aU
    Return the dot product of two arrays.

    This function is the equivalent of `numpy.dot` that takes masked values
    into account. Note that `strict` and `out` are in different position
    than in the method version. In order to maintain compatibility with the
    corresponding method, it is recommended that the optional arguments be
    treated as keyword only.  At some point that may be mandatory.

    Parameters
    ----------
    a, b : masked_array_like
        Inputs arrays.
    strict : bool, optional
        Whether masked data are propagated (True) or set to 0 (False) for
        the computation. Default is False.  Propagating the mask means that
        if a masked value appears in a row or column, the whole row or
        column is considered masked.
    out : masked_array, optional
        Output argument. This must have the exact kind that would be returned
        if it was not used. In particular, it must have the right type, must be
        C-contiguous, and its dtype must be the dtype that would be returned
        for `dot(a,b)`. This is a performance feature. Therefore, if these
        conditions are not met, an exception is raised, instead of attempting
        to be flexible.

        .. versionadded:: 1.10.2

    See Also
    --------
    numpy.dot : Equivalent function for ndarrays.

    Examples
    --------
    >>> a = np.ma.array([[1, 2, 3], [4, 5, 6]], mask=[[1, 0, 0], [0, 0, 0]])
    >>> b = np.ma.array([[1, 2], [3, 4], [5, 6]], mask=[[1, 0], [0, 0], [0, 0]])
    >>> np.ma.dot(a, b)
    masked_array(
      data=[[21, 26],
            [45, 64]],
      mask=[[False, False],
            [False, False]],
      fill_value=999999)
    >>> np.ma.dot(a, b, strict=True)
    masked_array(
      data=[[--, --],
            [--, 64]],
      mask=[[ True,  True],
            [ True, False]],
      fill_value=999999)

    Trr�r�)rr�r�rZr�rNr0rlrfrwrjror�rIrrqrp)	rSr�r�rt�am�bmr�r�r�s	         r�r�r��s���j��~�~�
�7�1�:�:��?�?�b�g�a�j�j�A�o�o��
�V�q�[�[���1�6�A�:�.�.�A���1�6�A�:�.�.�A�A���1�6�A�:�.�.�A���1�6�A�:�.�.�A�
�q�/�/�	�B�
�q�/�/�	�B�
�{��F�6�!�Q�<�<���1���.�.��
�V�B��^�^�O��
�7�1�:�:��?�?��
�1�
�
�A�
�F�F�&�q�!�,�,�-�-��	�
�
�a�������F�6�!�Q�<�<���1���s�y�9�9���8�>�Q�W�$�$�����(�3�3�C�I�
��r�2�s�y�!�!�!�
��s�y�#�)�,�,�,��
r�c���t|d��}t|d��}|jdkrd|_|jdkrd|_tj||���t��S)z�
    Returns the inner product of a and b for arrays of floating point types.

    Like the generic NumPy equivalent the product sum is over the last dimension
    of a and b. The first argument is not conjugated.

    rr�)rNr�r�rrbrlr)rSr�r�r�s    r�rbrb�sb��
��1���B�	��1���B�	�w�!�|�|����	�w�!�|�|����
�8�B���� � ��-�-�-r�z Masked values are replaced by 0.c���t|d�����}t|d�����}tj||��}t	|��}t	|��}|t
ur|t
urt
|��St|��}t|��}tdtjd|z
d|z
��z
d���}t
||���S)r�rr�Fr�r�)	rNr�rr�rYr�rxrZrs)rSr�r�r�r�r�r�r�s        r�r�r�s���	��1���	�	�	�	�B�	��1���	�	�	�	�B�
���R���A�	����B�	����B�	�V�|�|��f����A����	�a���B�	�a���B��!�b�h�q�2�v�q�2�v�.�.�.�U�;�;�;�A����"�"�"�"r�c�:�|r�|t|��tjtj|��t���|���|tjtj|��t���t|��|���z}|t|��t|��|���}nS|t|��t|����}|t
|d��t
|d��|���}t||���S)z:
    Helper function for ma.correlate and ma.convolve
    rr�rr�)rZrr�r�rrXrNrx)r�rSr,r��propagate_maskrorms       r��_convolve_or_correlater�s���
8�
�A�l�1�o�o�r�w�r�x��{�{�$�?�?�?�d�K�K�K�
�A�b�g�b�h�q�k�k��.�.�.��Q���d�K�K�K�
L�	
��q�����W�Q�Z�Z�d�3�3�3�����<��?�?�"�\�!�_�_�$4�5�5�5���q���1���v�a��|�|�$�7�7�7����4�(�(�(�(r��validc�<�ttj||||��S)a�
    Cross-correlation of two 1-dimensional sequences.

    Parameters
    ----------
    a, v : array_like
        Input sequences.
    mode : {'valid', 'same', 'full'}, optional
        Refer to the `np.convolve` docstring.  Note that the default
        is 'valid', unlike `convolve`, which uses 'full'.
    propagate_mask : bool
        If True, then a result element is masked if any masked element contributes towards it.
        If False, then a result element is only masked if no non-masked element
        contribute towards it

    Returns
    -------
    out : MaskedArray
        Discrete cross-correlation of `a` and `v`.

    See Also
    --------
    numpy.correlate : Equivalent function in the top-level NumPy module.
    )r�rr>�rSr,r�r�s    r�r>r>)s��2"�"�,��1�d�N�K�K�Kr�rc�<�ttj||||��S)a�
    Returns the discrete, linear convolution of two one-dimensional sequences.

    Parameters
    ----------
    a, v : array_like
        Input sequences.
    mode : {'valid', 'same', 'full'}, optional
        Refer to the `np.convolve` docstring.
    propagate_mask : bool
        If True, then if any masked element is included in the sum for a result
        element, then the result is masked.
        If False, then the result element is only masked if no non-masked cells
        contribute towards it

    Returns
    -------
    out : MaskedArray
        Discrete, linear convolution of `a` and `v`.

    See Also
    --------
    numpy.convolve : Equivalent function in the top-level NumPy module.
    )r�rr<r�s    r�r<r<Es��2"�"�+�q�!�T�>�J�J�Jr�c���tt|��t|����}|turGt|��}t|��}t	j||��}|���S|rmt|��}t|��}t	j||��}t||d���}|�d���d��SdS)a
    Return True if all entries of a and b are equal, using
    fill_value as a truth value where either or both are masked.

    Parameters
    ----------
    a, b : array_like
        Input arrays to compare.
    fill_value : bool, optional
        Whether masked values in a or b are considered equal (True) or not
        (False).

    Returns
    -------
    y : bool
        Returns True if the two arrays are equal within the given
        tolerance, False otherwise. If either array contains NaN,
        then False is returned.

    See Also
    --------
    all, any
    numpy.ma.allclose

    Examples
    --------
    >>> a = np.ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1])
    >>> a
    masked_array(data=[10000000000.0, 1e-07, --],
                 mask=[False, False,  True],
           fill_value=1e+20)

    >>> b = np.array([1e10, 1e-7, -42.0])
    >>> b
    array([  1.00000000e+10,   1.00000000e-07,  -4.20000000e+01])
    >>> np.ma.allequal(a, b, fill_value=False)
    False
    >>> np.ma.allequal(a, b)
    True

    F)ror=TN)	rvrYr�rXr�rKrrrN)rSr�rMr�r�rr�r�s        r�rras���T	���
�
�G�A�J�J�'�'�A��F�{�{��A�J�J���A�J�J���K��1�����u�u�w�w��	���A�J�J���A�J�J���K��1����
�1�1�5�
)�
)�
)���y�y����"�"�4�(�(�(��ur�c
��t|d���}t|d���}|jjdkr2tj|d��}|j|krt||d���}tt
|��t
|����}tjt|d|������d��}	tj	|	ttj|��d��k��sdStj
|	��sUttt||z
��||t|��zz��|��}
tj	|
��Stj	t||	||	k|����sdS||	}||	}ttt||z
��||t|��zz��|��}
tj	|
��S)aL
    Returns True if two arrays are element-wise equal within a tolerance.

    This function is equivalent to `allclose` except that masked values
    are treated as equal (default) or unequal, depending on the `masked_equal`
    argument.

    Parameters
    ----------
    a, b : array_like
        Input arrays to compare.
    masked_equal : bool, optional
        Whether masked values in `a` and `b` are considered equal (True) or not
        (False). They are considered equal by default.
    rtol : float, optional
        Relative tolerance. The relative difference is equal to ``rtol * b``.
        Default is 1e-5.
    atol : float, optional
        Absolute tolerance. The absolute difference is equal to `atol`.
        Default is 1e-8.

    Returns
    -------
    y : bool
        Returns True if the two arrays are equal within the given
        tolerance, False otherwise. If either array contains NaN, then
        False is returned.

    See Also
    --------
    all, any
    numpy.allclose : the non-masked `allclose`.

    Notes
    -----
    If the following equation is element-wise True, then `allclose` returns
    True::

      absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`))

    Return True if all elements of `a` and `b` are equal subject to
    given tolerances.

    Examples
    --------
    >>> a = np.ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1])
    >>> a
    masked_array(data=[10000000000.0, 1e-07, --],
                 mask=[False, False,  True],
           fill_value=1e+20)
    >>> b = np.ma.array([1e10, 1e-8, -42.0], mask=[0, 0, 1])
    >>> np.ma.allclose(a, b)
    False

    >>> a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1])
    >>> b = np.ma.array([1.00001e10, 1e-9, -42.0], mask=[0, 0, 1])
    >>> np.ma.allclose(a, b)
    True
    >>> np.ma.allclose(a, b, masked_equal=False)
    False

    Masked values are not compared directly.

    >>> a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1])
    >>> b = np.ma.array([1.00001e10, 1e-9, 42.0], mask=[0, 0, 1])
    >>> np.ma.allclose(a, b)
    True
    >>> np.ma.allclose(a, b, masked_equal=False)
    False

    Fr�r�r�)rr=)r=ro)
rxrr(r�result_typervrY�isinfrNrr!rkr)rSr�ryrAr@r�rrr��xinfr�s           r�rr�s���P	�Q�U�#�#�#�A��Q�U�#�#�#�A�	�w�|�s�����q�"�%�%���7�e����Q�e�%�8�8�8�A����
�
�G�A�J�J�'�'�A�
�8�L���Q�7�7�7�8�8�?�?��F�F�D�
�6�$�&���!���e�4�4�4�5�5���u�
�6�$�<�<���:�h�q�1�u�o�o�t�d�X�a�[�[�6H�/H�I�I��
!�
!���v�a�y�y��
�6�&��4��A�d�G�+�\�:�:�;�;���u�	�4�%��A�	�4�%��A��z�(�1�q�5�/�/�4�$��!���2D�+D�E�E��	�	�A��6�!�9�9�r�c�4�|pd}t||ddd|���S)a�
    Convert the input to a masked array of the given data-type.

    No copy is performed if the input is already an `ndarray`. If `a` is
    a subclass of `MaskedArray`, a base class `MaskedArray` is returned.

    Parameters
    ----------
    a : array_like
        Input data, in any form that can be converted to a masked array. This
        includes lists, lists of tuples, tuples, tuples of tuples, tuples
        of lists, ndarrays and masked arrays.
    dtype : dtype, optional
        By default, the data-type is inferred from the input data.
    order : {'C', 'F'}, optional
        Whether to use row-major ('C') or column-major ('FORTRAN') memory
        representation.  Default is 'C'.

    Returns
    -------
    out : MaskedArray
        Masked array interpretation of `a`.

    See Also
    --------
    asanyarray : Similar to `asarray`, but conserves subclasses.

    Examples
    --------
    >>> x = np.arange(10.).reshape(2, 5)
    >>> x
    array([[0., 1., 2., 3., 4.],
           [5., 6., 7., 8., 9.]])
    >>> np.ma.asarray(x)
    masked_array(
      data=[[0., 1., 2., 3., 4.],
            [5., 6., 7., 8., 9.]],
      mask=False,
      fill_value=1e+20)
    >>> type(np.ma.asarray(x))
    <class 'numpy.ma.core.MaskedArray'>

    r�FT)rr=r�rir��rx)rSrr�s   r�r0r0 s2��X
�L�S�E����U�d�#�5�2�2�2�2r�c�r�t|t��r|�||jkr|St||ddd���S)ae
    Convert the input to a masked array, conserving subclasses.

    If `a` is a subclass of `MaskedArray`, its class is conserved.
    No copy is performed if the input is already an `ndarray`.

    Parameters
    ----------
    a : array_like
        Input data, in any form that can be converted to an array.
    dtype : dtype, optional
        By default, the data-type is inferred from the input data.
    order : {'C', 'F'}, optional
        Whether to use row-major ('C') or column-major ('FORTRAN') memory
        representation.  Default is 'C'.

    Returns
    -------
    out : MaskedArray
        MaskedArray interpretation of `a`.

    See Also
    --------
    asarray : Similar to `asanyarray`, but does not conserve subclass.

    Examples
    --------
    >>> x = np.arange(10.).reshape(2, 5)
    >>> x
    array([[0., 1., 2., 3., 4.],
           [5., 6., 7., 8., 9.]])
    >>> np.ma.asanyarray(x)
    masked_array(
      data=[[0., 1., 2., 3., 4.],
            [5., 6., 7., 8., 9.]],
      mask=False,
      fill_value=1e+20)
    >>> type(np.ma.asanyarray(x))
    <class 'numpy.ma.core.MaskedArray'>

    NFT)rr=r�ri)r!rrrx)rSrs  r�r/r/8 sE��X�!�[�!�!��u�}����8H�8H������U�d�$�O�O�O�Or�r�c� �td���)Nz1fromfile() not yet implemented for a MaskedArray.r�)�filerrArs    r��fromfiler�n s��
�;�=�=�=r�c�<�t|d|d���S)a�
    Build a masked array from a suitable flexible-type array.

    The input array has to have a data-type with ``_data`` and ``_mask``
    fields. This type of array is output by `MaskedArray.toflex`.

    Parameters
    ----------
    fxarray : ndarray
        The structured input array, containing ``_data`` and ``_mask``
        fields. If present, other fields are discarded.

    Returns
    -------
    result : MaskedArray
        The constructed masked array.

    See Also
    --------
    MaskedArray.toflex : Build a flexible-type array from a masked array.

    Examples
    --------
    >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[0] + [1, 0] * 4)
    >>> rec = x.toflex()
    >>> rec
    array([[(0, False), (1,  True), (2, False)],
           [(3,  True), (4, False), (5,  True)],
           [(6, False), (7,  True), (8, False)]],
          dtype=[('_data', '<i8'), ('_mask', '?')])
    >>> x2 = np.ma.fromflex(rec)
    >>> x2
    masked_array(
      data=[[0, --, 2],
            [--, 4, --],
            [6, --, 8]],
      mask=[[False,  True, False],
            [ True, False,  True],
            [False,  True, False]],
      fill_value=999999)

    Extra fields can be present in the structured array but are discarded:

    >>> dt = [('_data', '<i4'), ('_mask', '|b1'), ('field3', '<f4')]
    >>> rec2 = np.zeros((2, 2), dtype=dt)
    >>> rec2
    array([[(0, False, 0.), (0, False, 0.)],
           [(0, False, 0.), (0, False, 0.)]],
          dtype=[('_data', '<i4'), ('_mask', '?'), ('field3', '<f4')])
    >>> y = np.ma.fromflex(rec2)
    >>> y
    masked_array(
      data=[[0, 0],
            [0, 0]],
      mask=[[False, False],
            [False, False]],
      fill_value=999999,
      dtype=int32)

    rjrqr�r�)�fxarrays r�rVrVs s"��z���(�w�w�/?�@�@�@�@r�c�0�eZdZdZdZdd�Zd�Zd�Zd�ZdS)�_convert2maz�
    Convert functions from numpy to numpy.ma.

    Parameters
    ----------
        _methodname : string
            Name of the method to transform.

    Nc��tt|��|_|�||��|_|pi|_dSr)r�r�_funcr�r��_extras)r}ry�np_ret�	np_ma_retrxs     r�r~z_convert2ma.__init__� s7���R��*�*��
��{�{�6�9�5�5����|�����r�c��t|jdd��}t|j��}|r/|�|||��}|r|jj�|�d�}||z}|S)r�r�Nr")r�r�r��_replace_return_typer�)r}r�r�r�r�s     r�r�z_convert2ma.getdoc� so���d�j�)�T�2�2��"�4�:�.�.���	��+�+�C���C�C�C��
<�"&�*�"5�"5�s�s�s�;����)�C��
r�c
��||vr3td|�d|�d|�d|jj�d|jj�d����|�||��S)a
        Replace documentation of ``np`` function's return type.

        Replaces it with the proper type for the ``np.ma`` function.

        Parameters
        ----------
        doc : str
            The documentation of the ``np`` method.
        np_ret : str
            The return type string of the ``np`` method that we want to
            replace. (e.g. "out : ndarray")
        np_ma_ret : str
            The return type string of the ``np.ma`` method.
            (e.g. "out : MaskedArray")
        zFailed to replace `z` with `z-`. The documentation string for return type, z(, is not found in the docstring for `np.z`. Fix the docstring for `np.z0` or update the expected string for return type.)r�r�r��replace)r}r�r�r�s    r�r�z _convert2ma._replace_return_type� s���"�����>�f�>�>�i�>�>�=C�>�>�26�*�2E�>�>�.2�Z�-@�>�>�>���
��{�{�6�9�-�-�-r�c�|�|j}t|���|��}|D]}|�|��||<�|jj|i|���t��}d|vr|�dd��|_	d|vr(t|�dd����|_|S)NrMr�r�F)r��set�intersection�popr�r�rlrr*rMrr�)r}r�rxr��
common_params�prUs       r�r�z_convert2ma.__call__� s����,���F���0�0��9�9�
��	'�	'�A����A���G�A�J�J�$���$�d�5�f�5�5�:�:�;�G�G���=�(�(� '���L�$� ?� ?�F����&�&�#�G�K�K��U�$C�$C�D�D�F���
r�r)r�r�r�r�r~r�r�r�r�r�r�r�r�� sf���������G�$�$�$�$�

�
�
�.�.�.�8
�
�
�
�
r�r�r#)rMr�zarange : ndarrayzarange : MaskedArray)rxr�r�r6zclipped_array : ndarrayzclipped_array : MaskedArrayrIz
out : ndarrayzout : MaskedArrayrJ)r�r�rUzout: MaskedArrayrWzfromfunction : anyzfromfunction: MaskedArrayr_raz'grid : one ndarray or tuple of ndarraysz/grid : one MaskedArray or tuple of MaskedArraysr�r�r�zsqueezed : ndarrayzsqueezed : MaskedArrayr�r�c�&�t||g|��S)aAppend values to the end of an array.

    .. versionadded:: 1.9.0

    Parameters
    ----------
    a : array_like
        Values are appended to a copy of this array.
    b : array_like
        These values are appended to a copy of `a`.  It must be of the
        correct shape (the same shape as `a`, excluding `axis`).  If `axis`
        is not specified, `b` can be any shape and will be flattened
        before use.
    axis : int, optional
        The axis along which `v` are appended.  If `axis` is not given,
        both `a` and `b` are flattened before use.

    Returns
    -------
    append : MaskedArray
        A copy of `a` with `b` appended to `axis`.  Note that `append`
        does not occur in-place: a new array is allocated and filled.  If
        `axis` is None, the result is a flattened array.

    See Also
    --------
    numpy.append : Equivalent function in the top-level NumPy module.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = ma.masked_values([1, 2, 3], 2)
    >>> b = ma.masked_values([[4, 5, 6], [7, 8, 9]], 7)
    >>> ma.append(a, b)
    masked_array(data=[1, --, 3, 4, 5, 6, --, 8, 9],
                 mask=[False,  True, False, False, False, False,  True, False,
                       False],
           fill_value=999999)
    )r:)rSr�r�s   r�r"r"H!s��P��1�v�t�$�$�$r�r)T)FT)TT)r=r>TTr3r2r�r1r0)Nr�r�)FN)r�T)rT)Tr=r>r/(r�rvr�rCr��textwrapr��	functoolsr�numpyr�numpy.core.umathr+r��numpy.core.numerictypes�numerictypesr��
numpy.corerr�rrrrr	r
rr�numpy.lib.function_baser�numpy.compatr
rrrrr�numpy.core.numericr�__all__rr�r_r�r�r�r�r�rrr)r,�
datetime64�timedelta64�half�single�double�
longdouble�csingle�cdouble�clongdouble�float_types_list�_minvalsr:r��_maxvalsr7rr$rDr5r�r�r>rPr�rVr7rNrfrX�get_datarOrxr�r�rzr�r�r�r�r�r�r�r�rLr;r�r?r(r'r�r@r�rrrMr�rRr4r�r.rpr�rlrnrmr�r&r$r%r*rr�r�r)rKr�rkr\rjr[rorrqr�rrr1r2r3r^rHr�rSr�rTr�r�r�rtrY�get_maskrZrfr�rsrurrvrPr"r�rzr{r~rr�ryr|r�r�r�r}rKr�r]r[�dedentr.rfrQr}rrr&r�rerhrdr`rwr�rxrgror�r�r�r~rr rr!r8rBrCr=rFr]r`r�r�r�r�r�r�r�r�rEr�r�r�r�r�r�rAr�r�r,r+r-r�r9r:rErir�r�r�r�r�r�r�r�r�rGr�r5r�r�r�rbrcr�r�r�r>r<rrr0r/r�r�rVr�r#r6rIrJrUrWr_rar�r�r�r�r�r"r�r�r��<module>rsr����,��������������������	�	�	�	����������� � � � � � � � � �(�(�(�(�(�(�(�(�(�'�'�'�'�'�'�D�D�D�D�D�D�D�D�D�D�D�D�D�D�D�D�!�!�!�!�!�!�)�)�)�)�)�)���������������������3�3�3�3�3�3�"�"�"��H�8��	��!����	�	�	�	�	�}�	�	�	����8
>�
>�
>� 	�	�	�"	�	�	�	�	�i�	�	�	�	�	�	�	�	��	�	�	��#��������	�	��
�?�?�A�&3�b�m�E�1�&=�&=�N�5�1�9�s�?�#�&4�b�n�U�A�&>�&>�N�5�1�9�s�?�#�#��G�R�Y��	�2�=��J��
�B�N�<��
�_�
�
���>�>�)9�"�1�"�)=�>�>�>�?�?�?�
���Q�Q�;K�B�C�C�;P�Q�Q�Q�R�R�R�
�_�
�
���?�?�*:�2�A�2�*>�?�?�?�@�@�@�
���Q�Q�;K�B�C�C�;P�Q�Q�Q�R�R�R�����*(�(�(�4<�4<�4<�n<�<�<�0<�0<�0<�f0<�0<�0<�f���@) �) �) �X>�>�>�B
�
�
����@6�6�6�6�r���60�0�0�0�f���T�d�8
�8
�8
�8
�t=�=�=�����;�;�;�;�;�;�;�;�2F�F�F�F�F�F�F�F�$K�K�K�K�K�K�K�K�*
<�
<�
<�
<�
<�
<�
<�
<� 
6�
6�
6�
6�
6�
6�
6�
6� -�-�-�-�-�-�-�-�G�G�G�G�G�L�G�G�G�TP�P�P�P�P�\�P�P�P�hH�H�H�H�H�|�H�H�H�X��E�I�&�&��!�!�%�/�2�2�	���E�I�&�&����E�I�&�&��	�	�u�|�	,�	,��
�
��
�
.�
.����U�Z�(�(����U�Z�(�(����U�Z�(�(��&�&�u�~�6�6�6��h���e�$�$����U�Z�(�(�� � ���0�0����e�k�*�*����U�Z�(�(��	�	�r�y�	)�	)��#�#�E�$5�6�6����U�Z��0�0��5�5�7�7����E�I�s�*�N�3�/�/�1�1����U�Z��+�^�C�0�0�2�2����e�k�3�,�n�S�1�1�	3�	3����E�I�s�&�J�u�-�-�/�/��	�	�u�|�S�3�3�D�#�>�>�
@�
@��	�	�u�|�S�3�3�D�#�>�>�
@�
@��
�
��
�s� 3� 3�C� 8� 8�:�:��
�
��
�s� 4� 4�\�;� O� O�Q�Q����U�Y�'�'��!�!�%�.�1�1��!�!�%�.�!�Q�7�7��
 �
 ����S�
9�
9����u�{�+�+�����"�"�5�?�3�3�	��	��
#�
#�E�$4�
5�
5�
��
��&�&�u�':�;�;�
��
����e�j�)�)�����
 �
 ���
/�
/�����$�$�U�%6�7�7��
 �
 ��!2�A�q�
9�
9�
@��
#�
#�E�$4�
5�
5�
����$�$�U�%6�7�7��$�$�U�%6�7�7��
#�
#�E�$4�
5�
5�
�$�$�U�%6�7�7����u�{�+�+��
"�	!�%�,�0A�0A�0C�0C�Q��	J�	J��&�&�u�'8�'8�'8�':�':�A�q�B�B��'�'��(:�(9�(9�(;�(;�Q��C�C��$�$�U�_�%6�%6�%8�%8�!�Q�
@�
@�	����
�,=�,=�,?�,?��A�F�F����u�y�*;�*;�*=�*=�q�!�D�D�����@C�C�C�3�3�3�B8'�8'�8'�v��2�2�2�jA�A�A�H����D��V�V�V�V�r/�/�/�/�d@�@�@�5I�5I�5I�5I�p58�58�58�p+-�+�����w�w�w�w�t9�9�9�9�4?�?�?�?�46�6�6�6�4<�<�<�<�4;�;�;�;�4����@%1�%1�%1�%1�P%1�%1�%1�%1�PAC�AC�AC�AC�HE�E�E�E�P!�!�!�!�P-�-�-�-�-�-�-�-�`)�(��.�.�����$�$�
�X�_��
�
��X�_��
�
��h�o��
�
�
�h�o��
�
�+����DC�C�C�4�4�4�n*�*�*�*�Zi�i�i�i�i�i�i�i�Xn8�n8�n8�n8�n8�'�n8�n8�n8�bqH�H�H�D�D�D�D�D�K�D�D�D�X0&�0&�0&�f����q4�q4�q4�q4�q4�[�q4�q4�q4�h+�N�,�,�,��	�����d��$�$��$�d�!�
@�
@�
@�
@��$��
�2�2�2�tA�A�A�A�A��A�A�A�F�D�T�B�K�	6�	6�	6�	6��o�%����D�T�B�K�	6�	6�	6�	6��o�%����D�T�B�K�6�6�6�6��o�%���&-�&-�&-�&-�&-�&-�&-�&-�R�k�%�����;�v�&�&�&�	�D��k�%�����;�z�D�1�1�1��
�+�i�
 �
 ��	��X�	�	���{�6�����;�z�"�"���k�-�(�(���k�%����
�
�U�]�G�5G�
H�
H���{�6����
�
�U�]�D�2D�
E�
E��
�+�i�
 �
 ���{�6����
�+�f�
�
����G����	��X�	�	���k�-�(�(���k�-�(�(���k�%�����k�%�����;�z�"�"����G�����k�%������G����:�:�:�:�K�K�K�K�Z
��X�	�	��	��X�	�	���K�d�$��QU�<�<�<�<��%�-���&
�&
�&
�&
�R#&�#&�#&�L9�9�9�9�x/�/�/�/�d'�'�'�*!'�!'�!'�HE�E�E�E�&$�$�$�N#G�#G�#G�#G�L&�&�&�&�&=�=�=�@!�!�!��w����"�"�"��� ��
�'�'�'�'��w������R�[���D�D�D�D�X �8�X)�X)�X)�X)�vH
�H
�H
�H
�V4�4�4�4�j	��
�
�
�$O�O�O�O�d.�.�.�����)�;�=�=��
���#�#�#�����)�;�=�=��
���)�)�)�&L�L�L�L�8K�K�K�K�87�7�7�7�ti�i�i�i�X.2�.2�.2�.2�b.P�.P�.P�.P�l�b�b�=�=�=�=�
=A�=A�=A�@G�G�G�G�G�G�G�G�T
����4�4�%�0�0�0��$�	
�
�
���{�
��4�4�%�0�0�0�$�+�	����	����4�4�%�0�0�0��!�		�	�	���[���!����
�
�[��� ����
�
�{��
�
(�����
�;���4�4�%�0�0�0��!�	�����+�
��4�4�%�0�0�0�4�?�	�����{�
��4�4�%�0�0�0��!�	����
�K���!�
�
�
�	�
�+�
��4�4�%�0�0�0��&�	����	����4�4�%�0�0�0��!�		�	�	���[���!����
�(%�(%�(%�(%�(%�(%r�