AlkantarClanX12

Your IP : 18.119.159.196


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__/extras.cpython-311.pyc

�

�܋f���@�dZgd�ZddlZddlZddlmZddlmZmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZddlZddlmZm
Zddl m!Z!dd	l"m#Z#dd
l$m%Z%ddl&m'Z'd�Z(dOd
�Z)e*fd�Z+d�Z,Gd�d��Z-Gd�de-��Z.Gd�de-��Z/Gd�de-��Z0Gd�de-��Z1e1d��Z2e1d��Z3e1d��Z4e/d��xZ5Z6e/d��Z7e/d��Z8e/d ��Z9e/d!��Z:e.d"��Z;e.d#��Z<d$�Z=d%�Z>ej>je>_d&�Z?e?j�Kej?jdej?j�@d'����A��d(ze?_dPejBd*�d+�ZCdQd,�ZDdPd-�ZEdOd.�ZFdOd/�ZGd0�ZHd1�ZIdOd2�ZJejBfd3�ZKejBfd4�ZLdRd5�ZMdSd6�ZNdTd7�ZOdTd8�ZPdSd9�ZQdSd:�ZRd;�ZSdTd<�ZTdUd>�ZUdVd?�ZVdd=ejBd=ejBfd@�ZWGdA�dBe'��ZXGdC�dDeX��ZYeY��ZZdWdE�Z[dF�Z\dOdG�Z]dH�Z^dOdI�Z_dJ�Z`dK�ZadL�ZbdOdM�Zcejdejcjecj��ec_dXdN�Zeejdejejeej��ee_dS)Yz�
Masked arrays add-ons.

A collection of utilities for `numpy.ma`.

:author: Pierre Gerard-Marchant
:contact: pierregm_at_uga_dot_edu
:version: $Id: extras.py 3473 2007-10-29 15:18:13Z jarrod.millman $

).�apply_along_axis�apply_over_axes�
atleast_1d�
atleast_2d�
atleast_3d�average�clump_masked�clump_unmasked�column_stack�
compress_cols�compress_nd�compress_rowcols�
compress_rows�count_masked�corrcoef�cov�diagflat�dot�dstack�ediff1d�flatnotmasked_contiguous�flatnotmasked_edges�hsplit�hstack�isin�in1d�intersect1d�	mask_cols�mask_rowcols�	mask_rows�
masked_all�masked_all_like�median�mr_�ndenumerate�notmasked_contiguous�notmasked_edges�polyfit�	row_stack�	setdiff1d�setxor1d�stack�unique�union1d�vander�vstack�N�)�core)�MaskedArray�MAError�add�array�asarray�concatenate�filled�count�getmask�getmaskarray�make_mask_descr�masked�masked_array�mask_or�nomask�ones�sort�zeros�getdata�get_masked_subclassr)�ndarrayr6)�normalize_axis_index)�normalize_axis_tuple)�_ureduce)�AxisConcatenatorc�F�t|tttf��S)z6
    Is seq a sequence (ndarray, list or tuple)?

    )�
isinstancerG�tuple�list)�seqs �F/opt/cloudlinux/venv/lib64/python3.11/site-packages/numpy/ma/extras.py�
issequencerR)s��
�c�G�U�D�1�2�2�2�c�J�t|��}|�|��S)a�
    Count the number of masked elements along the given axis.

    Parameters
    ----------
    arr : array_like
        An array with (possibly) masked elements.
    axis : int, optional
        Axis along which to count. If None (default), a flattened
        version of the array is used.

    Returns
    -------
    count : int, ndarray
        The total number of masked elements (axis=None) or the number
        of masked elements along each slice of the given axis.

    See Also
    --------
    MaskedArray.count : Count non-masked elements.

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

    When the `axis` keyword is used an array is returned.

    >>> ma.count_masked(a, axis=0)
    array([1, 1, 1])
    >>> ma.count_masked(a, axis=1)
    array([0, 2, 1])

    )r<�sum)�arr�axis�ms   rQrr1s"��d	�S���A��5�5��;�;�rSc	��ttj||��tj|t	|�������}|S)aC
    Empty masked array with all elements masked.

    Return an empty masked array of the given shape and dtype, where all the
    data are masked.

    Parameters
    ----------
    shape : int or tuple of ints
        Shape of the required MaskedArray, e.g., ``(2, 3)`` or ``2``.
    dtype : dtype, optional
        Data type of the output.

    Returns
    -------
    a : MaskedArray
        A masked array with all data masked.

    See Also
    --------
    masked_all_like : Empty masked array modelled on an existing array.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> ma.masked_all((3, 3))
    masked_array(
      data=[[--, --, --],
            [--, --, --],
            [--, --, --]],
      mask=[[ True,  True,  True],
            [ True,  True,  True],
            [ True,  True,  True]],
      fill_value=1e+20,
      dtype=float64)

    The `dtype` parameter defines the underlying data type.

    >>> a = ma.masked_all((3, 3))
    >>> a.dtype
    dtype('float64')
    >>> a = ma.masked_all((3, 3), dtype=np.int32)
    >>> a.dtype
    dtype('int32')

    ��mask)r?�np�emptyrBr=)�shape�dtype�as   rQr r gsF��^	�R�X�e�U�+�+��'�%���)?�)?�@�@�	B�	B�	B�A��HrSc���tj|���t��}tj|jt
|j�����|_|S)a�
    Empty masked array with the properties of an existing array.

    Return an empty masked array of the same shape and dtype as
    the array `arr`, where all the data are masked.

    Parameters
    ----------
    arr : ndarray
        An array describing the shape and dtype of the required MaskedArray.

    Returns
    -------
    a : MaskedArray
        A masked array with all data masked.

    Raises
    ------
    AttributeError
        If `arr` doesn't have a shape attribute (i.e. not an ndarray)

    See Also
    --------
    masked_all : Empty masked array with all elements masked.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> arr = np.zeros((2, 3), dtype=np.float32)
    >>> arr
    array([[0., 0., 0.],
           [0., 0., 0.]], dtype=float32)
    >>> ma.masked_all_like(arr)
    masked_array(
      data=[[--, --, --],
            [--, --, --]],
      mask=[[ True,  True,  True],
            [ True,  True,  True]],
      fill_value=1e+20,
      dtype=float32)

    The dtype of the masked array matches the dtype of `arr`.

    >>> arr.dtype
    dtype('float32')
    >>> ma.masked_all_like(arr).dtype
    dtype('float32')

    �r_)	r\�
empty_like�viewr3rBr^r=r_�_mask)rVr`s  rQr!r!�sI��d	�
�c������,�,�A��g�a�g�_�Q�W�%=�%=�>�>�>�A�G��HrSc�$�eZdZdZd�Zd�Zd�ZdS)�_fromnxfunctionaV
    Defines a wrapper to adapt NumPy functions to masked arrays.


    An instance of `_fromnxfunction` can be called with the same parameters
    as the wrapped NumPy function. The docstring of `newfunc` is adapted from
    the wrapped function as well, see `getdoc`.

    This class should not be used directly. Instead, one of its extensions that
    provides support for a specific type of input should be used.

    Parameters
    ----------
    funcname : str
        The name of the function to be adapted. The function should be
        in the NumPy namespace (i.e. ``np.funcname``).

    c�F�||_|���|_dS�N)�__name__�getdoc�__doc__)�self�funcnames  rQ�__init__z_fromnxfunction.__init__�s�� ��
��{�{�}�}����rSc���tt|jd��}t|dd��}|rH|jtj|��z}tj|d��}d�||f��SdS)aK
        Retrieve the docstring and signature from the function.

        The ``__doc__`` attribute of the function is used as the docstring for
        the new masked array version of the function. A note on application
        of the function to the mask is appended.

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

        Nrlz@The function is applied to both the _data and the _mask, if any.z

)�getattrr\rj�ma�get_object_signature�doc_note�join)rm�npfunc�doc�sigs    rQrkz_fromnxfunction.getdoc�sz����T�]�D�1�1���f�i��.�.���	+��-�"�"9�&�"A�"A�A�C��+�c�$<�=�=�C��;�;��S�z�*�*�*��rSc��dSri�)rm�args�paramss   rQ�__call__z_fromnxfunction.__call__s���rSN)rj�
__module__�__qualname__rlrorkr}rzrSrQrgrg�sK��������&%�%�%����,
�
�
�
�
rSrgc��eZdZdZd�ZdS)�_fromnxfunction_singlez�
    A version of `_fromnxfunction` that is called with a single array
    argument followed by auxiliary args that are passed verbatim for
    both the data and mask calls.
    c��tt|j��}t|t��rH||���g|�Ri|��}|t
|��g|�Ri|��}t||���S|tj|��g|�Ri|��}|t
|��g|�Ri|��}t||���S)NrZ)	rqr\rjrMrG�	__array__r<r?r7�rm�xr{r|�func�_d�_ms       rQr}z_fromnxfunction_single.__call__
s����r�4�=�)�)���a��!�!�	-���a�k�k�m�m�5�d�5�5�5�f�5�5�B���l�1�o�o�7��7�7�7��7�7�B����,�,�,�,���b�j��m�m�5�d�5�5�5�f�5�5�B���l�1�o�o�7��7�7�7��7�7�B����,�,�,�,rSN�rjr~rrlr}rzrSrQr�r�s-��������
	-�	-�	-�	-�	-rSr�c��eZdZdZd�ZdS)�_fromnxfunction_seqz�
    A version of `_fromnxfunction` that is called with a single sequence
    of arrays followed by auxiliary args that are passed verbatim for
    both the data and mask calls.
    c���tt|j��}|td�|D����g|�Ri|��}|td�|D����g|�Ri|��}t	||���S)Nc�6�g|]}tj|����Srz)r\r7��.0r`s  rQ�
<listcomp>z0_fromnxfunction_seq.__call__.<locals>.<listcomp>!s ��2�2�2�1���A���2�2�2rSc�,�g|]}t|����Srz)r<r�s  rQr�z0_fromnxfunction_seq.__call__.<locals>.<listcomp>"s��4�4�4�Q��a���4�4�4rSrZ)rqr\rjrNr?r�s       rQr}z_fromnxfunction_seq.__call__s����r�4�=�)�)��
�T�%�2�2��2�2�2�3�3�
E�d�
E�
E�
E�f�
E�
E��
�T�%�4�4�!�4�4�4�5�5�
G��
G�
G�
G��
G�
G���B�R�(�(�(�(rSNr�rzrSrQr�r�s-��������
)�)�)�)�)rSr�c��eZdZdZd�ZdS)�_fromnxfunction_argsa�
    A version of `_fromnxfunction` that is called with multiple array
    arguments. The first non-array-like input marks the beginning of the
    arguments that are passed verbatim for both the data and mask calls.
    Array arguments are processed independently and the results are
    returned in a list. If only one array is found, the return value is
    just the processed array instead of a list.
    c�F�tt|j��}g}t|��}t	|��dkret|d��rP|�|�d����t	|��dkrt|d���Pg}|D]]}|tj|��g|�Ri|��}|t|��g|�Ri|��}|�t||������^t	|��dkr|dS|S)Nr0rZr1)rqr\rjrO�lenrR�append�popr7r<r?)	rmr{r|r��arrays�resr�r�r�s	         rQr}z_fromnxfunction_args.__call__/s ���r�4�=�)�)�����D�z�z���$�i�i�!�m�m�
�4��7� 3� 3�m��M�M�$�(�(�1�+�+�&�&�&��$�i�i�!�m�m�
�4��7� 3� 3�m����	2�	2�A���b�j��m�m�5�d�5�5�5�f�5�5�B���l�1�o�o�7��7�7�7��7�7�B��J�J�|�B�R�0�0�0�1�1�1�1��v�;�;�!����q�6�M��
rSNr�rzrSrQr�r�&s-��������
�
�
�
�
rSr�c��eZdZdZd�ZdS)�_fromnxfunction_allargsa
    A version of `_fromnxfunction` that is called with multiple array
    arguments. Similar to `_fromnxfunction_args` except that all args
    are converted to arrays even if they are not so already. This makes
    it possible to process scalars as 1-D arrays. Only keyword arguments
    are passed through verbatim for the data and mask calls. Arrays
    arguments are processed independently and the results are returned
    in a list. If only one arg is present, the return value is just the
    processed array instead of a list.
    c�(�tt|j��}g}|D]W}|tj|��fi|��}|t	|��fi|��}|�t
||������Xt|��dkr|dS|S)NrZr1r0)rqr\rjr7r<r�r?r�)rmr{r|r�r�r�r�r�s        rQr}z _fromnxfunction_allargs.__call__Js����r�4�=�)�)�����	2�	2�A���b�j��m�m�.�.�v�.�.�B���l�1�o�o�0�0��0�0�B��J�J�|�B�R�0�0�0�1�1�1�1��t�9�9��>�>��q�6�M��
rSNr�rzrSrQr�r�?s-������	�	�	�	�	�	�	rSr�rrrr/rr
rr+rrc���d}|t|��krTt||d��r&|||||dz�<t||d���&|dz
}|t|��k�T|S)zFlatten a sequence in place.r0�__iter__r1)r��hasattr)rP�ks  rQ�flatten_inplacer�hsz��	�A���C���=�=��c�!�f�j�)�)�	$� ��V�C��1�q�5�	�N��c�!�f�j�)�)�	$�	�Q���
��C���=�=��JrSc�
�t|dd���}|j}t||��}dg|dz
z}tj|d��}tt
|����}|�|��tdd��||<tj	|j
���|��}	|�||��||t|�����g|�Ri|��}
tj|
��}|s#	t!|
��n#t"$rd}YnwxYwg}|�ra|�tj	|
��j��t	|	t(��}
|
|
t|��<tj|	��}d}||kr�|dxxdz
cc<d}|||	|krA|d|z
kr8||dz
xxdz
cc<d||<|dz}|||	|kr	|d|z
k�8|�||��||t|�����g|�Ri|��}
|
|
t|��<|�t|
��j��|dz
}||k��n7t|
dd���}
|���}tdd��g|
jz||<|�||��tj|	��}|	}t|j
��}	|
j
|	|<|�t|
��j��t/|	��}	t	|	t(��}
|
|
tt/|�������<d}||k�r&|dxxdz
cc<d}||||krA|d|z
kr8||dz
xxdz
cc<d||<|dz}||||kr	|d|z
k�8|�||��|�||��||t|�����g|�Ri|��}
|
|
tt/|�������<|�t|
��j��|dz
}||k��&tjtj	|�������}t3|d	��stj	|
|�
��}n*t|
|�
��}t5j|��|_|S)z0
    (This docstring should be overwritten)
    FT)�copy�subokr0r1�ON���rerb)r6�ndimrHr\rDrO�range�remove�slicer7r^�take�putrN�tolist�isscalarr��	TypeErrorr�r_�object�prodr�r��maxr�rr�default_fill_value�
fill_value)�func1drWrVr{�kwargs�nd�ind�i�indlist�outshaper��asscalar�dtypes�outarr�Ntotr��n�j�	holdshape�
max_dtypes�results                     rQrrrsC����%�t�
,�
,�
,�C�	��B���b�)�)�D��#��a��.�C�
���S���A��5��9�9�o�o�G��N�N�4�����D�$���A�d�G��z�#�)�$�$�)�)�'�2�2�H��E�E�'�3����
�&��U�1�8�8�:�:�&�&�'�
9�$�
9�
9�
9�&�
9�
9�C��{�3���H���	���H�H�H�H���	�	�	��H�H�H�	����
�F��.��
�
�b�j��o�o�+�,�,�,��x��(�(�� ��u�S�z�z���w�x� � ��
���$�h�h���G�G�G�q�L�G�G�G��A��q�6�X�a�[�(�(�q�A��F�|�|��A��E�
�
�
�a��
�
�
���A���Q����q�6�X�a�[�(�(�q�A��F�|�|�
�E�E�'�3�����&��U�1�8�8�:�:�.�.�/�A�$�A�A�A�&�A�A�C�!$�F�5��:�:���M�M�'�#�,�,�,�-�-�-�
��F�A��$�h�h���C�e�4�0�0�0��
�F�F�H�H���$��%�%�&���1��$��	���g�s�����w�x� � ���	���	�?�?��������
�
�g�c�l�l�(�)�)�)�"�8�,�,���x��(�(��58��u�_�Q�X�X�Z�Z�0�0�1�1�2�
���$�h�h���G�G�G�q�L�G�G�G��A��q�6�Y�q�\�)�)��Q��V����A��E�
�
�
�a��
�
�
���A���Q����q�6�Y�q�\�)�)��Q��V���
�E�E�'�3����
�E�E�'�3�����&��U�1�8�8�:�:�.�.�/�A�$�A�A�A�&�A�A�C�9<�F�5�������4�4�5�5�6��M�M�'�#�,�,�,�-�-�-�
��F�A��$�h�h���"�*�V�,�,�0�0�2�2�3�3�J��3�� � �:���F�*�5�5�5�����z�2�2�2���1�&�9�9����Ms�D&�&D5�4D5c�,�t|��}|j}t|��jdkr|f}|D]_}|dkr||z}||f}||�}|j|jkr|}�)tj||��}|j|jkr|}�Qtd���|S)z.
    (This docstring will be overwritten)
    r0z7function is not returning an array of the correct shape)r7r�r6rr�expand_dims�
ValueError)r�r`�axes�val�NrWr{r�s        rQrr�s����!�*�*�C�	��A��T�{�{��1����w���
9�
9���!�8�8��t�8�D��T�{���d�D�k���8�s�x����C�C��.��d�+�+�C��x�3�8�#�#���� �"8�9�9�9��JrS�Notesao

    Examples
    --------
    >>> a = np.ma.arange(24).reshape(2,3,4)
    >>> a[:,0,1] = np.ma.masked
    >>> a[:,1,:] = np.ma.masked
    >>> a
    masked_array(
      data=[[[0, --, 2, 3],
             [--, --, --, --],
             [8, 9, 10, 11]],
            [[12, --, 14, 15],
             [--, --, --, --],
             [20, 21, 22, 23]]],
      mask=[[[False,  True, False, False],
             [ True,  True,  True,  True],
             [False, False, False, False]],
            [[False,  True, False, False],
             [ True,  True,  True,  True],
             [False, False, False, False]]],
      fill_value=999999)
    >>> np.ma.apply_over_axes(np.ma.sum, a, [0,2])
    masked_array(
      data=[[[46],
             [--],
             [124]]],
      mask=[[[False],
             [ True],
             [False]]],
      fill_value=999999)

    Tuple axis arguments to ufuncs are equivalent:

    >>> np.ma.sum(a, axis=(0,2)).reshape((1,-1,1))
    masked_array(
      data=[[[46],
             [--],
             [124]]],
      mask=[[[False],
             [ True],
             [False]]],
      fill_value=999999)
    F)�keepdimsc�v�t|��}t|��}|tjuri}nd|i}|�=|j|fi|��}|j�|�|����}�n�t|��}	t|jjtj	tj
f��r!tj|j|	jd��}
ntj|j|	j��}
|j|	jkr�|�td���|	jdkrtd���|	jd|j|krtd���tj|	|jdz
d	z|	jzd
���}	|	�d|��}	|t$ur |	|jz}	|	xj|jzc_|	jd||
d
�|��}tj||	|
���j|fi|��|z}|r@|j|jkr,tj||j�����}||fS|S)a�

    Return the weighted average of array over the given axis.

    Parameters
    ----------
    a : array_like
        Data to be averaged.
        Masked entries are not taken into account in the computation.
    axis : int, optional
        Axis along which to average `a`. If None, averaging is done over
        the flattened array.
    weights : array_like, optional
        The importance that each element has in the computation of the average.
        The weights array can either be 1-D (in which case its length must be
        the size of `a` along the given axis) or of the same shape as `a`.
        If ``weights=None``, then all data in `a` are assumed to have a
        weight equal to one.  The 1-D calculation is::

            avg = sum(a * weights) / sum(weights)

        The only constraint on `weights` is that `sum(weights)` must not be 0.
    returned : bool, optional
        Flag indicating whether a tuple ``(result, sum of weights)``
        should be returned as output (True), or just the result (False).
        Default is False.
    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 original `a`.
        *Note:* `keepdims` will not work with instances of `numpy.matrix`
        or other classes whose methods do not support `keepdims`.

        .. versionadded:: 1.23.0

    Returns
    -------
    average, [sum_of_weights] : (tuple of) scalar or MaskedArray
        The average along the specified axis. When returned is `True`,
        return a tuple with the average as the first element and the sum
        of the weights as the second element. The return type is `np.float64`
        if `a` is of integer type and floats smaller than `float64`, or the
        input data-type, otherwise. If returned, `sum_of_weights` is always
        `float64`.

    Examples
    --------
    >>> a = np.ma.array([1., 2., 3., 4.], mask=[False, False, True, True])
    >>> np.ma.average(a, weights=[3, 1, 0, 0])
    1.25

    >>> x = np.ma.arange(6.).reshape(3, 2)
    >>> x
    masked_array(
      data=[[0., 1.],
            [2., 3.],
            [4., 5.]],
      mask=False,
      fill_value=1e+20)
    >>> avg, sumweights = np.ma.average(x, axis=0, weights=[1, 2, 3],
    ...                                 returned=True)
    >>> avg
    masked_array(data=[2.6666666666666665, 3.6666666666666665],
                 mask=[False, False],
           fill_value=1e+20)

    With ``keepdims=True``, the following result has shape (3, 1).

    >>> np.ma.average(x, axis=1, keepdims=True)
    masked_array(
      data=[[0.5],
            [2.5],
            [4.5]],
      mask=False,
      fill_value=1e+20)
    r�N�f8z;Axis must be specified when shapes of a and weights differ.r1z81D weights expected when shapes of a and weights differ.r0z5Length of weights not compatible with specified axis.)r1T�r�r�)rWr_rbrz)r7r;r\�_NoValue�meanr_�typer:�
issubclass�integer�bool_�result_typer^r�r�r��broadcast_to�swapaxesrAr[rU�multiplyr�)r`rW�weights�returnedr�rX�keepdims_kw�avg�scl�wgt�result_dtypes           rQrrse��Z	��
�
�A���
�
�A��2�;������!�8�,�����a�f�T�)�)�[�)�)���i�n�n�Q�W�W�T�]�]�+�+����g�����a�g�l�R�Z���$:�;�;�	>��>�!�'�3�9�d�C�C�L�L��>�!�'�3�9�=�=�L�
�7�c�i����|�������x�1�}�}��N�P�P�P��y��|�q�w�t�}�,�,� �K�M�M�M��/�#���q��$����'B�$�O�O�O�C��,�,�r�4�(�(�C��F�?�?����w�-�C��H�H����H�H��c�g�C�4�|�C�C�{�C�C��2�b�k�!�S� ,�.�.�.�.1�$�G�G�:E�G�G�IL�M�����9��	�!�!��/�#�s�y�1�1�6�6�8�8�C��C�x���
rSc��t|d��s`tjt|d���||||���}t	|tj��rd|jkrt|d���S|St|t||||���S)	a>	
    Compute the median along the specified axis.

    Returns the median of the array elements.

    Parameters
    ----------
    a : array_like
        Input array or object that can be converted to an array.
    axis : int, optional
        Axis along which the medians are computed. The default (None) is
        to compute the median along a flattened version of the array.
    out : ndarray, 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.
    overwrite_input : bool, optional
        If True, then allow use of memory of input array (a) for
        calculations. The input array will be modified by the call to
        median. This will save memory when you do not need to preserve
        the contents of the input array. Treat the input as undefined,
        but it will probably be fully or partially sorted. Default is
        False. Note that, if `overwrite_input` is True, and the input
        is not already an `ndarray`, an error will be raised.
    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 input array.

        .. versionadded:: 1.10.0

    Returns
    -------
    median : ndarray
        A new array holding the result is returned unless out is
        specified, in which case a reference to out is returned.
        Return data-type is `float64` for integers and floats smaller than
        `float64`, or the input data-type, otherwise.

    See Also
    --------
    mean

    Notes
    -----
    Given a vector ``V`` with ``N`` non masked values, the median of ``V``
    is the middle value of a sorted copy of ``V`` (``Vs``) - i.e.
    ``Vs[(N-1)/2]``, when ``N`` is odd, or ``{Vs[N/2 - 1] + Vs[N/2]}/2``
    when ``N`` is even.

    Examples
    --------
    >>> x = np.ma.array(np.arange(8), mask=[0]*4 + [1]*4)
    >>> np.ma.median(x)
    1.5

    >>> x = np.ma.array(np.arange(10).reshape(2, 5), mask=[0]*6 + [1]*4)
    >>> np.ma.median(x)
    2.5
    >>> np.ma.median(x, axis=-1, overwrite_input=True)
    masked_array(data=[2.0, 5.0],
                 mask=[False, False],
           fill_value=1e+20)

    r[Tr�)rW�out�overwrite_inputr�r1F�r�)r�r�rWr�r�)
r�r\r"rErMrGr�r?rJ�_median)r`rWr�r�r�rXs      rQr"r"�s���D�1�f�����I�g�a�t�,�,�,�4���'�
)�
)�
)���a���$�$�	��a�f������.�.�.�.��H��A�G�h�T�s�$3�5�5�5�5rSc����tj|jtj��r
tj}nd}|rG��+|������|���n,|��|���|�nt
|�|������d�nt��j����j	�dkrbtd��g�jz}tdd��|�<t|��}tj�
�|�|���S�jdk�r(tt���d��\}}�||zdz
|dz�}tj�jtj��rb�jdkrW|�|���}	|stj|	dd	|�
��}	tjj��|	���}	n|�
|���}	tj�|	��r8tj�j��stj����S|	St��d���}
|
dz}|
dzdk}tj|||dz
��}tj||g��
��}
tj�|
��
��}��fd�}||��tj�jtj��rktj�|�|���}	tj|	jdd|	j�
��tjj��|	���}	n"tj�
|�|���}	|	S)N)r�)rWr�r0)rWr�r1�)r�g@�safe)�castingr�T�rWr��rWc���tj�|��rXtj�j�d���|jz}tj����|j|<d|j|<dSdS)NTr�F)r\rr�	is_masked�allr[�minimum_fill_value�data)�s�rep�asortedrWs  ��rQ�replace_maskedz_median.<locals>.replace_maskedsq���
�5�?�?�1���	 ��F�7�<�d�T�B�B�B�B�a�f�L�C��%�2�2�7�;�;�A�F�3�K��A�F�3�K�K�K�	 �	 rS�unsafe)r\�
issubdtyper_�inexact�inf�ravelrCrHr�r^r�rNrrr��divmodr:�sizerU�true_divide�lib�utils�_median_nancheckr�r�r[r��wherer8�take_along_axisr�)r`rWr�r�r��indexer�idx�odd�midr��counts�h�l�lh�low_highr�r�s `              @rQr�r��sJ����
�}�Q�W�b�j�)�)���V�
�
��
��<��<��g�g�i�i�G��L�L�J�L�/�/�/�/�
�F�F���F�4�4�4��G�G��q�t�
�;�;�;���|����#�D�'�,�7�7���}�T��a�����;�;�-�'�,�.���a������
���.�.���u�z�z�'�'�*��3�z�?�?�?��|�q����%��.�.�!�,�,���S��c�C�i�!�m�C�!�G�+�,��
�=����
�3�3�	"���q�8H�8H����C�� � �A��
C��N�1�b�&�c�B�B�B�����-�-�g�q�$�?�?�A�A����S��!�!�A�
�5�?�?�1���	5�b�f�W�\�&:�&:�	5��5�+�+�G�4�4�4���
�7���
5�
5�
5�F��!��A��1�*��/�C�
���a��1����A�	���1��D�	)�	)�	)�B��!�'�2�D�9�9�9�H� � � � � � ��N�8����	�}�W�]�B�J�/�/�5��E�I�I�h�T�s�I�3�3��
��q�v�r�8���@�@�@�@��F�L�)�)�'�1�d�;�;����E�J�J�x�d��J�4�4���HrSc
�\�t|��}t|��}|�"tt|j����}nt||j��}|tus|���s|jS|�	��rtg��S|j}|D]�}ttt|����tt|dz|j����z��}|td��f|z|�|���fz}��|S)a�Suppress slices from multiple dimensions which contain masked values.

    Parameters
    ----------
    x : array_like, MaskedArray
        The array to operate on. If not a MaskedArray instance (or if no array
        elements are masked), `x` is interpreted as a MaskedArray with `mask`
        set to `nomask`.
    axis : tuple of ints or int, optional
        Which dimensions to suppress slices from can be configured with this
        parameter.
        - If axis is a tuple of ints, those are the axes to suppress slices from.
        - If axis is an int, then that is the only axis to suppress slices from.
        - If axis is None, all axis are selected.

    Returns
    -------
    compress_array : ndarray
        The compressed array.
    Nr1r�)
r7r;rNr�r�rIrA�any�_datar��nxarrayrOr�)r�rWrXr��axr�s      rQrr7s��*	��
�
�A���
�
�A��|��U�1�6�]�]�#�#���#�D�!�&�1�1��	�F�{�{�!�%�%�'�'�{��w���u�u�w�w���r�{�{���7�D��>�>���T�%��)�)�_�_�t�E�"�q�&�!�&�,A�,A�'B�'B�B�C�C���U�4�[�[�N�2�%�!�%�%�T�%�*:�*:�):�(<�<�=����KrSc�r�t|��jdkrtd���t||���S)a�
    Suppress the rows and/or columns of a 2-D array that contain
    masked values.

    The suppression behavior is selected with the `axis` parameter.

    - If axis is None, both rows and columns are suppressed.
    - If axis is 0, only rows are suppressed.
    - If axis is 1 or -1, only columns are suppressed.

    Parameters
    ----------
    x : array_like, MaskedArray
        The array to operate on.  If not a MaskedArray instance (or if no array
        elements are masked), `x` is interpreted as a MaskedArray with
        `mask` set to `nomask`. Must be a 2D array.
    axis : int, optional
        Axis along which to perform the operation. Default is None.

    Returns
    -------
    compressed_array : ndarray
        The compressed array.

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

    >>> np.ma.compress_rowcols(x)
    array([[7, 8]])
    >>> np.ma.compress_rowcols(x, 0)
    array([[6, 7, 8]])
    >>> np.ma.compress_rowcols(x, 1)
    array([[1, 2],
           [4, 5],
           [7, 8]])

    r�z*compress_rowcols works for 2D arrays only.r�)r7r��NotImplementedErrorr)r�rWs  rQr
r
bs:��d�q�z�z��!���!�"N�O�O�O��q�t�$�$�$�$rSc�t�t|��}|jdkrtd���t|d��S)z�
    Suppress whole rows of a 2-D array that contain masked values.

    This is equivalent to ``np.ma.compress_rowcols(a, 0)``, see
    `compress_rowcols` for details.

    See Also
    --------
    compress_rowcols

    r�z'compress_rows works for 2D arrays only.r0�r7r�rr
�r`s rQrr��9��	��
�
�A��v��{�{�!�"K�L�L�L��A�q�!�!�!rSc�t�t|��}|jdkrtd���t|d��S)z�
    Suppress whole columns of a 2-D array that contain masked values.

    This is equivalent to ``np.ma.compress_rowcols(a, 1)``, see
    `compress_rowcols` for details.

    See Also
    --------
    compress_rowcols

    r�z'compress_cols works for 2D arrays only.r1rrs rQrr�rrSc��t|d���}|jdkrtd���t|��}|tus|���s|S|���}|j���|_|s"t|tj|d��<|dvr&t|dd�tj|d��f<|S)	a�
    Mask rows and/or columns of a 2D array that contain masked values.

    Mask whole rows and/or columns of a 2D array that contain
    masked values.  The masking behavior is selected using the
    `axis` parameter.

      - If `axis` is None, rows *and* columns are masked.
      - If `axis` is 0, only rows are masked.
      - If `axis` is 1 or -1, only columns are masked.

    Parameters
    ----------
    a : array_like, MaskedArray
        The array to mask.  If not a MaskedArray instance (or if no array
        elements are masked), the result is a MaskedArray with `mask` set
        to `nomask` (False). Must be a 2D array.
    axis : int, optional
        Axis along which to perform the operation. If None, applies to a
        flattened version of the array.

    Returns
    -------
    a : MaskedArray
        A modified version of the input array, masked depending on the value
        of the `axis` parameter.

    Raises
    ------
    NotImplementedError
        If input array `a` is not 2D.

    See Also
    --------
    mask_rows : Mask rows of a 2D array that contain masked values.
    mask_cols : Mask cols of a 2D array that contain masked values.
    masked_where : Mask where a condition is met.

    Notes
    -----
    The input array's mask is modified by this function.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.zeros((3, 3), dtype=int)
    >>> a[1, 1] = 1
    >>> a
    array([[0, 0, 0],
           [0, 1, 0],
           [0, 0, 0]])
    >>> a = ma.masked_equal(a, 1)
    >>> a
    masked_array(
      data=[[0, 0, 0],
            [0, --, 0],
            [0, 0, 0]],
      mask=[[False, False, False],
            [False,  True, False],
            [False, False, False]],
      fill_value=1)
    >>> ma.mask_rowcols(a)
    masked_array(
      data=[[0, --, 0],
            [--, --, --],
            [0, --, 0]],
      mask=[[False,  True, False],
            [ True,  True,  True],
            [False,  True, False]],
      fill_value=1)

    Fr�r�z&mask_rowcols works for 2D arrays only.r0)Nr1r�Nr1)r6r�rr;rAr�nonzerorer�r>r\r,)r`rWrX�	maskedvals    rQrr�s���R	�a�u����A��v��{�{�!�"J�K�K�K���
�
�A��F�{�{�!�%�%�'�'�{����	�	���I��g�l�l�n�n�A�G��,�%+��"�)�I�a�L�
!�
!�"��}���(.��!�!�!�R�Y�y��|�
$�
$�
$�%��HrSc�v�|tjurtjdtd���t|d��S)a�
    Mask rows of a 2D array that contain masked values.

    This function is a shortcut to ``mask_rowcols`` with `axis` equal to 0.

    See Also
    --------
    mask_rowcols : Mask rows and/or columns of a 2D array.
    masked_where : Mask where a condition is met.

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

    >>> ma.mask_rows(a)
    masked_array(
      data=[[0, 0, 0],
            [--, --, --],
            [0, 0, 0]],
      mask=[[False, False, False],
            [ True,  True,  True],
            [False, False, False]],
      fill_value=1)

    �TThe axis argument has always been ignored, in future passing it will raise TypeErrorr���
stacklevelr0�r\r��warnings�warn�DeprecationWarningr�r`rWs  rQrrsM��T�2�;���	�
�
#�$6�1�	F�	F�	F�	F���1���rSc�v�|tjurtjdtd���t|d��S)a�
    Mask columns of a 2D array that contain masked values.

    This function is a shortcut to ``mask_rowcols`` with `axis` equal to 1.

    See Also
    --------
    mask_rowcols : Mask rows and/or columns of a 2D array.
    masked_where : Mask where a condition is met.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = np.zeros((3, 3), dtype=int)
    >>> a[1, 1] = 1
    >>> a
    array([[0, 0, 0],
           [0, 1, 0],
           [0, 0, 0]])
    >>> a = ma.masked_equal(a, 1)
    >>> a
    masked_array(
      data=[[0, 0, 0],
            [0, --, 0],
            [0, 0, 0]],
      mask=[[False, False, False],
            [False,  True, False],
            [False, False, False]],
      fill_value=1)
    >>> ma.mask_cols(a)
    masked_array(
      data=[[0, --, 0],
            [0, --, 0],
            [0, --, 0]],
      mask=[[False,  True, False],
            [False,  True, False],
            [False,  True, False]],
      fill_value=1)

    rr�rr1rr"s  rQrrIsM��R�2�;���	�
�
#�$6�1�	F�	F�	F�	F���1���rSc�
�tj|��j}|dd�|dd�z
}|g}|�|�d|��|�|�|��t|��dkrt
|��}|S)a!
    Compute the differences between consecutive elements of an array.

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

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

    r1Nr�r0)rr�
asanyarray�flat�insertr�r�r)rV�to_end�to_begin�edr�s     rQrrs���
�-��
�
�
!�C�	�Q�R�R��3�s��s�8�	�B��T�F����
�
�a��"�"�"�
���
�
�f����
�6�{�{�a����F�^�^��
�IrSc��tj|||���}t|t��rBt	|��}|d�t��|d<t|��}n|�t��}|S)a.
    Finds the unique elements of an array.

    Masked values are considered the same element (masked). The output array
    is always a masked array. See `numpy.unique` for more details.

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

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = [1, 2, 1000, 2, 3]
    >>> mask = [0, 0, 1, 0, 0]
    >>> masked_a = ma.masked_array(a, mask)
    >>> masked_a
    masked_array(data=[1, 2, --, 2, 3],
                mask=[False, False,  True, False, False],
        fill_value=999999)
    >>> ma.unique(masked_a)
    masked_array(data=[1, 2, 3, --],
                mask=[False, False, False,  True],
        fill_value=999999)
    >>> ma.unique(masked_a, return_index=True)
    (masked_array(data=[1, 2, 3, --],
                mask=[False, False, False,  True],
        fill_value=999999), array([0, 1, 4, 2]))
    >>> ma.unique(masked_a, return_inverse=True)
    (masked_array(data=[1, 2, 3, --],
                mask=[False, False, False,  True],
        fill_value=999999), array([0, 1, 3, 1, 2]))
    >>> ma.unique(masked_a, return_index=True, return_inverse=True)
    (masked_array(data=[1, 2, 3, --],
                mask=[False, False, False,  True],
        fill_value=999999), array([0, 1, 4, 2]), array([0, 1, 3, 1, 2]))
    )�return_index�return_inverser0)r\r,rMrNrOrdr3)�ar1r,r-�outputs    rQr,r,�s~��L�Y�s�$0�&4�6�6�6�F��&�%� � �*��f�����1�I�N�N�;�/�/��q�	��v��������[�)�)���MrSc��|rtj||f��}n0tjt|��t|��f��}|���|dd�|dd�|dd�kS)a>
    Returns the unique elements common to both arrays.

    Masked values are considered equal one to the other.
    The output is always a masked array.

    See `numpy.intersect1d` for more details.

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

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

    Nr�r1)rrr8r,rC)r.�ar2�
assume_unique�auxs    rQrr�sx��.�9��n�c�3�Z�(�(����n�f�S�k�k�6�#�;�;�7�8�8���H�H�J�J�J��s��s�8�C����G�s�3�B�3�x�'�(�(rSc�n�|st|��}t|��}tj||f��}|jdkr|S|���|���}tjdg|dd�|dd�kdgf��}|dd�|dd�k}||S)z�
    Set exclusive-or of 1-D arrays with unique elements.

    The output is always a masked array. See `numpy.setxor1d` for more details.

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

    r0Tr1Nr�)r,rrr8r�rCr9)r.r1r2r3�auxf�flag�flag2s       rQr*r*�s������S�k�k���S�k�k��
�.�#�s��
$�
$�C�
�x�1�}�}��
��H�H�J�J�J��:�:�<�<�D�
�>�D�6�D����H��S�b�S�	�$9�T�F�C�D�D�D�
�!�"�"�X��c�r�c��
"�E��u�:�rSc���|s#t|d���\}}t|��}tj||f��}|�d���}||}|r|dd�|dd�k}n|dd�|dd�k}tj||gf��}	|�d���dt	|���}
|r|	|
S|	|
|S)a�
    Test whether each element of an array is also present in a second
    array.

    The output is always a masked array. See `numpy.in1d` for more details.

    We recommend using :func:`isin` instead of `in1d` for new code.

    See Also
    --------
    isin       : Version of this function that preserves the shape of ar1.
    numpy.in1d : Equivalent function for ndarrays.

    Notes
    -----
    .. versionadded:: 1.4.0

    T)r-�	mergesort)�kindr1Nr�)r,rrr8�argsortr�)r.r1r2�invert�rev_idx�ar�order�sar�bool_arr6�indxs           rQrr	s���&���c�$�7�7�7���W��S�k�k��	���c�
�	#�	#�B�
�J�J�K�J�(�(�E�
�U�)�C�
�(��q�r�r�7�c�#�2�#�h�&����q�r�r�7�c�#�2�#�h�&��
�>�7�V�H�-�.�.�D��=�=�k�=�*�*�9�C��H�H�9�5�D��#��D�z���D�z�'�"�"rSc��tj|��}t||||����|j��S)a|
    Calculates `element in test_elements`, broadcasting over
    `element` only.

    The output is always a masked array of the same shape as `element`.
    See `numpy.isin` for more details.

    See Also
    --------
    in1d       : Flattened version of this function.
    numpy.isin : Equivalent function for ndarrays.

    Notes
    -----
    .. versionadded:: 1.13.0

    �r2r<)rrr7r�reshaper^)�element�
test_elementsr2r<s    rQrr3sB��$�j��!�!�G����m�����&�w�w�}�5�5�6rSc�L�ttj||fd�����S)z�
    Union of two arrays.

    The output is always a masked array. See `numpy.union1d` for more details.

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

    Nr�)r,rrr8)r.r1s  rQr-r-Js%���"�.�#�s��$�7�7�7�8�8�8rSc���|r'tj|�����}nt|��}t|��}|t	||dd���S)a�
    Set difference of 1D arrays with unique elements.

    The output is always a masked array. See `numpy.setdiff1d` for more
    details.

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

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

    TrD)rrr7r�r,r)r.r1r2s   rQr)r)XsY��(���j��o�o�#�#�%�%����S�k�k���S�k�k���t�C��D��>�>�>�?�?rSTc�F�tj|ddt���}tj|��}|s#|���rtd���|jddkrd}tt|����}d|z
}|rtd��df}ndtd��f}|�.tj|���t��}�nt|ddt�	��}tj|��}|s#|���rtd���|���s|���rN|j|jkr>tj
||��}	|	tur |	x}x|_x|_}d|_d|_tj||f|��}tjtj||f|�����t��}||�|�
��|z}|||fS)z_
    Private function for the computation of covariance and correlation
    coefficients.

    r�T)�ndminr�r_zCannot process masked data.r0r1NF)r�rKr_r�)rrr6�floatr<rr�r^�int�boolr�r\�logical_not�astype�
logical_orrAre�_sharedmaskr8r�)
r��y�rowvar�allow_masked�xmaskrW�tup�xnotmask�ymask�common_masks
          rQ�
_covhelperr[ys���	���!�$�e�4�4�4�A��O�A���E��8�E�I�I�K�K�8��6�7�7�7��w�q�z�Q�����
��f���
�
�F��v�:�D�
�"��T�{�{�D�!����U�4�[�[�!���y��>�%�(�(�/�/��4�4����!�%�q��6�6�6�����"�"���	<��	�	���	<��:�;�;�;��9�9�;�;�	*�%�)�)�+�+�	*��w�!�'�!�!� �m�E�5�9�9���f�,�,�8C�C�E�C�A�G�C�a�g��$)�A�M�$)�A�M��N�A�q�6�4�(�(���>�"�.�%����"F�"F�G�G�N�N�s�S�S������V��	�	�S�	!�!�A�
�x�� � rSc�
�|�"|t|��krtd���|�|rd}nd}t||||��\}}}|s_tj|j|��dz|z
}t	|j|���d���|z���}n^tj||j��dz|z
}t	||j���d���|z���}|S)aK
    Estimate the covariance matrix.

    Except for the handling of missing data this function does the same as
    `numpy.cov`. For more details and examples, see `numpy.cov`.

    By default, masked values are recognized as such. If `x` and `y` have the
    same shape, a common mask is allocated: if ``x[i,j]`` is masked, then
    ``y[i,j]`` will also be masked.
    Setting `allow_masked` to False will raise an exception if values are
    missing in either of the input arrays.

    Parameters
    ----------
    x : array_like
        A 1-D or 2-D array containing multiple variables and observations.
        Each row of `x` represents a variable, and each column a single
        observation of all those variables. Also see `rowvar` below.
    y : array_like, optional
        An additional set of variables and observations. `y` has the same
        shape as `x`.
    rowvar : bool, optional
        If `rowvar` is True (default), then each row represents a
        variable, with observations in the columns. Otherwise, the relationship
        is transposed: each column represents a variable, while the rows
        contain observations.
    bias : bool, optional
        Default normalization (False) is by ``(N-1)``, where ``N`` is the
        number of observations given (unbiased estimate). If `bias` is True,
        then normalization is by ``N``. This keyword can be overridden by
        the keyword ``ddof`` in numpy versions >= 1.5.
    allow_masked : bool, optional
        If True, masked values are propagated pair-wise: if a value is masked
        in `x`, the corresponding value is masked in `y`.
        If False, raises a `ValueError` exception when some values are missing.
    ddof : {None, int}, optional
        If not ``None`` normalization is by ``(N - ddof)``, where ``N`` is
        the number of observations; this overrides the value implied by
        ``bias``. The default value is ``None``.

        .. versionadded:: 1.5

    Raises
    ------
    ValueError
        Raised if some values are missing and `allow_masked` is False.

    See Also
    --------
    numpy.cov

    Nzddof must be an integerr0r1��?F��strict)rMr�r[r\r�T�conj�squeeze)	r�rSrT�biasrU�ddofrX�factr�s	         rQrr�s��l��D�C��I�I�-�-��2�3�3�3��|��	��D�D��D�&�q�!�V�\�B�B��Q��&��E��v�h�j�(�+�+�b�0�4�7���a�c�1�6�6�8�8�E�2�2�2�T�9�B�B�D�D����v�h��
�+�+�b�0�4�7���a�������E�2�2�2�T�9�B�B�D�D���MrSc
��d}|tjus|tjurtj|td���t||||��\}}}|s\tj|j|��dz}t
|j|���d���|z�	��}	n[tj||j��dz}t
||j���d���|z�	��}		tj|	��}
n#t$rYdSwxYw|�
��r4tjtj�|
|
����}�n}t#|
��}d|_|jd|z
}|r�t)|dz
��D]�}
t)|
dz|��D]}}t+t-||
||f�����d���}tjtj�|����x||
|f<|||
f<�~��n�t)|dz
��D]�}
t)|
dz|��D]�}t+t-|d	d	�|
f|d	d	�|ff�����d���}tjtj�|����x||
|f<|||
f<����|	|zS)
a6
    Return Pearson product-moment correlation coefficients.

    Except for the handling of missing data this function does the same as
    `numpy.corrcoef`. For more details and examples, see `numpy.corrcoef`.

    Parameters
    ----------
    x : array_like
        A 1-D or 2-D array containing multiple variables and observations.
        Each row of `x` represents a variable, and each column a single
        observation of all those variables. Also see `rowvar` below.
    y : array_like, optional
        An additional set of variables and observations. `y` has the same
        shape as `x`.
    rowvar : bool, optional
        If `rowvar` is True (default), then each row represents a
        variable, with observations in the columns. Otherwise, the relationship
        is transposed: each column represents a variable, while the rows
        contain observations.
    bias : _NoValue, optional
        Has no effect, do not use.

        .. deprecated:: 1.10.0
    allow_masked : bool, optional
        If True, masked values are propagated pair-wise: if a value is masked
        in `x`, the corresponding value is masked in `y`.
        If False, raises an exception.  Because `bias` is deprecated, this
        argument needs to be treated as keyword only to avoid a warning.
    ddof : _NoValue, optional
        Has no effect, do not use.

        .. deprecated:: 1.10.0

    See Also
    --------
    numpy.corrcoef : Equivalent function in top-level NumPy module.
    cov : Estimate the covariance matrix.

    Notes
    -----
    This function accepts but discards arguments `bias` and `ddof`.  This is
    for backwards compatibility with previous versions of this function.  These
    arguments had no effect on the return values of the function and can be
    safely ignored in this and previous versions of numpy.
    z/bias and ddof have no effect and are deprecatedr�rr]Fr^r1r�N)r\r�rr r!r[rr`rarbrr�diagonalr�r��sqrtr��outerrrRr^r�rr/�var�reduce)r�rSrTrcrUrd�msgrXre�c�diag�_denomr�r�r��_xs                rQrr�s���`<�C��2�;���$�b�k�"9�"9��
�c�-�!�<�<�<�<�&�q�!�V�\�B�B��Q��&��@��v�h�j�(�+�+�b�0��
���a�f�f�h�h�u�
-�
-�
-��
4�=�=�?�?����v�h��
�+�+�b�0��
��A�C�H�H�J�J�u�
-�
-�
-��
4�=�=�?�?����{�1�~�~���������q�q������|�|�~�~�R�����*�*�4��6�6�7�7����$����"���
�G�A��J����
	R��1�q�5�\�\�
R�
R���q�1�u�a���R�R�A�"�6�1�Q�4��1��,�#7�#7�8�8�<�<�!�<�D�D�B�24�'�"�+�:L�:L�R�:P�:P�2Q�2Q�Q�F�1�a�4�L�6�!�Q�$�<�<�R�
R�
�1�q�5�\�\�
R�
R���q�1�u�a���R�R�A�"�"�A�a�a�a��d�G�Q�q�q�q�!�t�W�#5�6�6�8�8�8;�������24�'�"�+�:L�:L�R�:P�:P�2Q�2Q�Q�F�1�a�4�L�6�!�Q�$�<�<�R�
�v�:�s�D � 
D.�-D.c�R��eZdZdZee��Ze�fd���Z�fd�Z�xZ	S)�MAxisConcatenatorz�
    Translate slice objects to concatenation along an axis.

    For documentation on usage, see `mr_class`.

    See Also
    --------
    mr_class

    c���t���|jd���}t||j���S)NFr�rZ)�super�makematr�r6r[)�clsrVr��	__class__s   �rQruzMAxisConcatenator.makematTs5����w�w���s�x�e��4�4���T���)�)�)�)rSc���t|t��rtd���t���|��S)NzUnavailable for masked array.)rM�strr4rt�__getitem__)rm�keyrws  �rQrzzMAxisConcatenator.__getitem__]s<����c�3���	;��9�:�:�:��w�w�"�"�3�'�'�'rS)
rjr~rrl�staticmethodr8�classmethodrurz�
__classcell__)rws@rQrrrrGsv�������	�	��,�{�+�+�K��*�*�*�*��[�*�(�(�(�(�(�(�(�(�(rSrrc��eZdZdZd�ZdS)�mr_classa�
    Translate slice objects to concatenation along the first axis.

    This is the masked array version of `lib.index_tricks.RClass`.

    See Also
    --------
    lib.index_tricks.RClass

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

    c�<�t�|d��dS)Nr0)rrro)rms rQrozmr_class.__init__ws���"�"�4��+�+�+�+�+rSN)rjr~rrlrorzrSrQr�r�es-��������",�,�,�,�,rSr�c#�K�ttj|��t|��j��D]\}}|s|V��|s|dt
fV�� dS)a�
    Multidimensional index iterator.

    Return an iterator yielding pairs of array coordinates and values,
    skipping elements that are masked. With `compressed=False`,
    `ma.masked` is yielded as the value of masked elements. This
    behavior differs from that of `numpy.ndenumerate`, which yields the
    value of the underlying data array.

    Notes
    -----
    .. versionadded:: 1.23.0

    Parameters
    ----------
    a : array_like
        An array with (possibly) masked elements.
    compressed : bool, optional
        If True (default), masked elements are skipped.

    See Also
    --------
    numpy.ndenumerate : Equivalent function ignoring any mask.

    Examples
    --------
    >>> a = np.ma.arange(9).reshape((3, 3))
    >>> a[1, 0] = np.ma.masked
    >>> a[1, 2] = np.ma.masked
    >>> a[2, 1] = np.ma.masked
    >>> a
    masked_array(
      data=[[0, 1, 2],
            [--, 4, --],
            [6, --, 8]],
      mask=[[False, False, False],
            [ True, False,  True],
            [False,  True, False]],
      fill_value=999999)
    >>> for index, x in np.ma.ndenumerate(a):
    ...     print(index, x)
    (0, 0) 0
    (0, 1) 1
    (0, 2) 2
    (1, 1) 4
    (2, 0) 6
    (2, 2) 8

    >>> for index, x in np.ma.ndenumerate(a, compressed=False):
    ...     print(index, x)
    (0, 0) 0
    (0, 1) 1
    (0, 2) 2
    (1, 0) --
    (1, 1) 4
    (1, 2) --
    (2, 0) 6
    (2, 1) --
    (2, 2) 8
    r0N)�zipr\r$r<r&r>)r`�
compressed�itr[s    rQr$r$�ss����z���q�)�)�<��?�?�+?�@�@� � ���D��	 ��H�H�H�H��	 ��Q�%��-�����	 � rSc��t|��}|tustj|��stjd|jdz
g��Stj|��}t|��dkr
|ddgSdS)a�
    Find the indices of the first and last unmasked values.

    Expects a 1-D `MaskedArray`, returns None if all values are masked.

    Parameters
    ----------
    a : array_like
        Input 1-D `MaskedArray`

    Returns
    -------
    edges : ndarray or None
        The indices of first and last non-masked value in the array.
        Returns None if all values are masked.

    See Also
    --------
    flatnotmasked_contiguous, notmasked_contiguous, notmasked_edges
    clump_masked, clump_unmasked

    Notes
    -----
    Only accepts 1-D arrays.

    Examples
    --------
    >>> a = np.ma.arange(10)
    >>> np.ma.flatnotmasked_edges(a)
    array([0, 9])

    >>> mask = (a < 3) | (a > 8) | (a == 5)
    >>> a[mask] = np.ma.masked
    >>> np.array(a[~a.mask])
    array([3, 4, 6, 7, 8])

    >>> np.ma.flatnotmasked_edges(a)
    array([3, 8])

    >>> a[:] = np.ma.masked
    >>> print(np.ma.flatnotmasked_edges(a))
    None

    r0r1r�N)r;rAr\rr6r��flatnonzeror�)r`rX�unmaskeds   rQrr�su��Z	��
�
�A��F�{�{�"�&��)�)�{��x��A�F�Q�J��(�(�(��~�q�b�!�!�H�
�8�}�}�q�����B�� � ��trSc����t|��}��|jdkrt|��St|��}t	tj|j��tj|g|jz������t��fd�t|j��D����t��fd�t|j��D����gS)a_
    Find the indices of the first and last unmasked values along an axis.

    If all values are masked, return None.  Otherwise, return a list
    of two tuples, corresponding to the indices of the first and last
    unmasked values respectively.

    Parameters
    ----------
    a : array_like
        The input array.
    axis : int, optional
        Axis along which to perform the operation.
        If None (default), applies to a flattened version of the array.

    Returns
    -------
    edges : ndarray or list
        An array of start and end indexes if there are any masked data in
        the array. If there are no masked data in the array, `edges` is a
        list of the first and last index.

    See Also
    --------
    flatnotmasked_contiguous, flatnotmasked_edges, notmasked_contiguous
    clump_masked, clump_unmasked

    Examples
    --------
    >>> a = np.arange(9).reshape((3, 3))
    >>> m = np.zeros_like(a)
    >>> m[1:, 1:] = 1

    >>> am = np.ma.array(a, mask=m)
    >>> np.array(am[~am.mask])
    array([0, 1, 2, 3, 6])

    >>> np.ma.notmasked_edges(am)
    array([0, 6])

    Nr1rZc�j��g|]/}�|���������0Srz)�minr��r�r�rWrs  ��rQr�z#notmasked_edges.<locals>.<listcomp>+�5���H�H�H�Q�3�q�6�:�:�d�#�#�.�.�0�0�H�H�HrSc�j��g|]/}�|���������0Srz)r�r�r�s  ��rQr�z#notmasked_edges.<locals>.<listcomp>,r�rS)
r7r�rr<r6r\�indicesr^rNr�)r`rWrXrs ` @rQr&r&�s�����T	��
�
�A��|�q�v��{�{�"�1�%�%�%��Q���A�
��
�1�7�#�#�"�*�a�S�1�6�\�*B�*B�
C�
C�
C�C��H�H�H�H�H�%���-�-�H�H�H�I�I��H�H�H�H�H�%���-�-�H�H�H�I�I�M�MrSc�T�t|��}|turtd|j��gSd}g}t	j|�����D]N\}}tt|����}|s&|�	t|||z����||z
}�O|S)a�
    Find contiguous unmasked data in a masked array.

    Parameters
    ----------
    a : array_like
        The input array.

    Returns
    -------
    slice_list : list
        A sorted sequence of `slice` objects (start index, end index).

        .. versionchanged:: 1.15.0
            Now returns an empty list instead of None for a fully masked array

    See Also
    --------
    flatnotmasked_edges, notmasked_contiguous, notmasked_edges
    clump_masked, clump_unmasked

    Notes
    -----
    Only accepts 2-D arrays at most.

    Examples
    --------
    >>> a = np.ma.arange(10)
    >>> np.ma.flatnotmasked_contiguous(a)
    [slice(0, 10, None)]

    >>> mask = (a < 3) | (a > 8) | (a == 5)
    >>> a[mask] = np.ma.masked
    >>> np.array(a[~a.mask])
    array([3, 4, 6, 7, 8])

    >>> np.ma.flatnotmasked_contiguous(a)
    [slice(3, 5, None), slice(6, 9, None)]
    >>> a[:] = np.ma.masked
    >>> np.ma.flatnotmasked_contiguous(a)
    []

    r0)
r;rAr�r��	itertools�groupbyr�r�rOr�)r`rXr�r�r��gr�s       rQrr/s���X	��
�
�A��F�{�{��a��� � �!�!�	�A�
�F��#�A�G�G�I�I�.�.�����A���Q���L�L���	+��M�M�%��1�q�5�/�/�*�*�*�	�Q�����MrSc	�z�t|��}|j}|dkrtd���|�|dkrt|��Sg}|dzdz}ddg}t	dd��||<t|j|��D]<}|||<|�t|t|�������=|S)a�
    Find contiguous unmasked data in a masked array along the given axis.

    Parameters
    ----------
    a : array_like
        The input array.
    axis : int, optional
        Axis along which to perform the operation.
        If None (default), applies to a flattened version of the array, and this
        is the same as `flatnotmasked_contiguous`.

    Returns
    -------
    endpoints : list
        A list of slices (start and end indexes) of unmasked indexes
        in the array.

        If the input is 2d and axis is specified, the result is a list of lists.

    See Also
    --------
    flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges
    clump_masked, clump_unmasked

    Notes
    -----
    Only accepts 2-D arrays at most.

    Examples
    --------
    >>> a = np.arange(12).reshape((3, 4))
    >>> mask = np.zeros_like(a)
    >>> mask[1:, :-1] = 1; mask[0, 1] = 1; mask[-1, 0] = 0
    >>> ma = np.ma.array(a, mask=mask)
    >>> ma
    masked_array(
      data=[[0, --, 2, 3],
            [--, --, --, 7],
            [8, --, --, 11]],
      mask=[[False,  True, False, False],
            [ True,  True,  True, False],
            [False,  True,  True, False]],
      fill_value=999999)
    >>> np.array(ma[~ma.mask])
    array([ 0,  2,  3,  7, 8, 11])

    >>> np.ma.notmasked_contiguous(ma)
    [slice(0, 1, None), slice(2, 4, None), slice(7, 9, None), slice(11, 12, None)]

    >>> np.ma.notmasked_contiguous(ma, axis=0)
    [[slice(0, 1, None), slice(2, 3, None)], [], [slice(0, 1, None)], [slice(0, 3, None)]]

    >>> np.ma.notmasked_contiguous(ma, axis=1)
    [[slice(0, 1, None), slice(2, 4, None)], [slice(3, 4, None)], [slice(0, 1, None), slice(3, 4, None)]]

    r�z&Currently limited to at most 2D array.Nr1r0)	r7r�rrr�r�r^r�rN)r`rWr�r��otherrr�s       rQr%r%hs���t	��
�
�A�	
��B�	�A�v�v�!�"J�K�K�K��|�r�Q�w�w�'��*�*�*�
�F�
�A�X��N�E��a�&�C��d�D�!�!�C��I�
�1�7�5�>�
"�
"�?�?����E�
��
�
�.�q��s���}�=�=�>�>�>�>��MrSc
��|jdkr|���}|dd�|dd�z���}|ddz}|dr�t|��dkrt	d|j��gSt	d|d��g}|�d�t|ddd�|ddd���D����nAt|��dkrgSd�t|ddd�|ddd���D��}|dr.|�t	|d|j����|S)zv
    Finds the clumps (groups of data with the same values) for a 1D bool array.

    Returns a series of slices.
    r1Nr�r0c3�<K�|]\}}t||��V��dSri�r��r��left�rights   rQ�	<genexpr>z_ezclump.<locals>.<genexpr>�sL����B�B�!�d�E���e�$�$�B�B�B�B�B�BrSr�c�4�g|]\}}t||����Srzr�r�s   rQr�z_ezclump.<locals>.<listcomp>�s&��N�N�N�K�D�%�U�4��
�
�N�N�NrS)	r�r�rr�r�r��extendr�r�)r[r�rs   rQ�_ezclumpr��sn���y�1�}�}��z�z�|�|������8�d�3�B�3�i��
(�
(�
*�
*�C�

�a�&�1�*�C��A�w�O��s�8�8�q�=�=��!�T�Y�'�'�(�(�
�1�c�!�f�
�
���	���B�B�%(��Q�r�!�V��c�!�$�Q�$�i�%@�%@�B�B�B�	C�	C�	C�	C��s�8�8�q�=�=��I�N�N�3�s�5�B�q�5�z�3�q�t�!�t�9�3M�3M�N�N�N���B�x�,�	����s�2�w��	�*�*�+�+�+��HrSc��t|dt��}|turtd|j��gSt	|��S)a�
    Return list of slices corresponding to the unmasked clumps of a 1-D array.
    (A "clump" is defined as a contiguous region of the array).

    Parameters
    ----------
    a : ndarray
        A one-dimensional masked array.

    Returns
    -------
    slices : list of slice
        The list of slices, one for each continuous region of unmasked
        elements in `a`.

    Notes
    -----
    .. versionadded:: 1.4.0

    See Also
    --------
    flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges
    notmasked_contiguous, clump_masked

    Examples
    --------
    >>> a = np.ma.masked_array(np.arange(10))
    >>> a[[0, 1, 2, 6, 8, 9]] = np.ma.masked
    >>> np.ma.clump_unmasked(a)
    [slice(3, 6, None), slice(7, 8, None)]

    rer0)rqrAr�r�r��r`r[s  rQr	r	�sB��B�1�g�v�&�&�D��v�~�~��a��� � �!�!��T�E�?�?�rSc�^�tj|��}|turgSt|��S)a

    Returns a list of slices corresponding to the masked clumps of a 1-D array.
    (A "clump" is defined as a contiguous region of the array).

    Parameters
    ----------
    a : ndarray
        A one-dimensional masked array.

    Returns
    -------
    slices : list of slice
        The list of slices, one for each continuous region of masked elements
        in `a`.

    Notes
    -----
    .. versionadded:: 1.4.0

    See Also
    --------
    flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges
    notmasked_contiguous, clump_unmasked

    Examples
    --------
    >>> a = np.ma.masked_array(np.arange(10))
    >>> a[[0, 1, 2, 6, 8, 9]] = np.ma.masked
    >>> np.ma.clump_masked(a)
    [slice(0, 3, None), slice(6, 7, None), slice(8, 10, None)]

    )rrr;rAr�r�s  rQrr�s,��B�:�a�=�=�D��v�~�~��	��D�>�>�rSc�j�tj||��}t|��}|turd||<|S)zD
    Masked values in the input array result in rows of zeros.

    r0)r\r.r;rA)r�r��_vanderrXs    rQr.r.%s5��
�i��1�o�o�G���
�
�A��������
��NrSc	���t|��}t|��}t|��}|jdkrt|t|����}nZ|jdkr@tt	|����}|t
urt||dd�df��}nt
d���|�qt|��}|jdkrt
d���|jd|jdkrt
d���t|t|����}|t
ur3|}	|�||	}tj	||	||	|||||��Stj	|||||||��S)zE
    Any masked values in x is propagated in y, and vice-versa.

    r1r�Nr0z Expected a 1D or 2D array for y!z expected a 1-d array for weightsz(expected w and y to have the same length)
r7r;r�r@rrAr�r^r\r')
r�rS�deg�rcond�full�wrrX�my�not_ms
          rQr'r'3s^��
	��
�
�A���
�
�A���
�
�A��v��{�{��A�w�q�z�z�"�"���	
��1���
�Y�q�\�\�
"�
"��
�V�����2�a�a�a��d�8�$�$�A���:�;�;�;��}��A�J�J���6�Q�;�;��>�?�?�?��7�1�:�����#�#��F�G�G�G��A�w�q�z�z�"�"����������=��%��A��z�!�E�(�A�e�H�c�5�$��3�G�G�G��z�!�Q��U�D�!�S�9�9�9rSri)NNF)NNFF)NN)FF)F)NTT)NTFTN)T)NFNF)frl�__all__r�r�r2rrr3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFr�numpyr\rGr�numpy.core.multiarrayrH�numpy.core.numericrI�numpy.lib.function_baserJ�numpy.lib.index_tricksrKrRrrLr r!rgr�r�r�r�rrrr/r(rr
rr+rrr�rr�find�rstripr�rr"r�rr
rrrrrrr,rr*rrr-r)r[rrrrr�r#r$rr&rr%r�r	rr.rtr'rzrSrQ�<module>r�sJ��	�	�
�
�
������������������������������������������������������������������+�+�+�+�+�+�+�+�6�6�6�6�6�6�3�3�3�3�3�3�,�,�,�,�,�,�3�3�3�3�3�3�3�3�3�3�3�3�3�l"�1
�1
�1
�1
�h4
�4
�4
�t/
�/
�/
�/
�/
�/
�/
�/
�d-�-�-�-�-�_�-�-�-�$
)�
)�
)�
)�
)�/�
)�
)�
)������?����2�����o����.%�
$�\�
2�
2�
�
$�
$�\�
2�
2�
�
$�
$�\�
2�
2�
�(�(��2�2�2���	�	�X�	&�	&��"�"�>�2�2��	�	�X�	&�	&����G�$�$��	�	��	)�	)��!�!�*�-�-�����O�O�O�`�.�6������2��&� �0�8�1��	�	#�	(�	(��	1�	1�1�3�39�6�8�8�+�-�O��`A��[�A�A�A�A�A�HL5�L5�L5�L5�^R
�R
�R
�R
�j(�(�(�(�V4%�4%�4%�4%�n"�"�"�$"�"�"�$V
�V
�V
�V
�r�k�0�0�0�0�f�k�/�/�/�/�l����:/�/�/�/�d)�)�)�)�@����6'#�'#�'#�'#�T6�6�6�6�.9�9�9�@�@�@�@�B(!�(!�(!�(!�VF�F�F�F�R�t�"�+�D��+�T�T�T�T�t(�(�(�(�(�(�(�(�(�<,�,�,�,�,� �,�,�,�*�h�j�j��A �A �A �A �H4�4�4�n0M�0M�0M�0M�f6�6�6�rJ�J�J�J�Z
�
�
�:$�$�$�N$�$�$�X	�	�	�	����R�Y�.���?�?��� :� :� :� :�D�"�+�b�j�0�'�/�B�B����rS