
    rbi                    D   d Z g dZddlZddlZddlZddlZddlmZm	Z	 ddl
mZ ddlmZ ddlmZmZ dd	lmZ dd
lmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' d Z(d>dZ)e*fdZ+d Z,d Z-e-d             Z.e-d             Z/e-d             Z0 e0ej1                  Z1 e0ej2                  Z2 e0ej3                  Z3 e/ej4                  xZ4Z5 e/ej6                  Z6 e/ej7                  Z7 e/ej8                  Z8 e/ej9                  Z9 e.ej:                  Z: e.ej;                  Z;d Z<d Z=ej=        j         e=_         d Z>e>j         Kej>        j         dej>        j         ?                    d                   @                                dz   e>_         d?ejA        ddZBd@dZCd?dZDd>dZEd>dZFd ZGd  ZHd>d!ZIejA        fd"ZJejA        fd#ZKdAd$ZLdBd%ZMdCd&ZNdCd'ZOdBd(ZPdBd)ZQd* ZRdCd+ZSdDd-ZTdEd.ZUdDd/ZV G d0 d1e          ZW G d2 d3eW          ZX eX            ZYdFd4ZZd5 Z[d>d6Z\d7 Z]d>d8Z^d9 Z_d: Z`d; Zad>d<Zb ejc        ejb        j         ebj                   eb_         dGd=Zd ejc        ejd        j         edj                   ed_         dS )Hz
Masked arrays add-ons.

A collection of utilities for `numpy.ma`.

:author: Pierre Gerard-Marchant
:contact: pierregm_at_uga_dot_edu

).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)arrayndarray)_ureduce)AxisConcatenator)normalize_axis_indexnormalize_axis_tuple   )core)MAErrorMaskedArrayaddr1   asarrayconcatenatecountr   filledget_masked_subclassgetdatagetmaskgetmaskarraymake_mask_descrmask_ormaskedmasked_arraynomaskonessortzerosc                 F    t          | t          t          t          f          S )z6
    Is seq a sequence (ndarray, list or tuple)?

    )
isinstancer2   tuplelist)seqs    _/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/numpy/ma/extras.py
issequencerR   :   s    
 cGUD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 as np
    >>> a = np.arange(9).reshape((3,3))
    >>> a = np.ma.array(a)
    >>> 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)
    >>> np.ma.count_masked(a)
    3

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

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

    )rC   sum)arraxisms      rQ   r   r   B   s"    d 	SA55;;rS   c           	          t          t          j        | |          t          j        | t	          |                              }|S )a  
    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.

    Notes
    -----
    Unlike other masked array creation functions (e.g. `numpy.ma.zeros`,
    `numpy.ma.ones`, `numpy.ma.full`), `masked_all` does not initialize the
    values of the array, and may therefore be marginally faster. However,
    the values stored in the newly allocated array are arbitrary. For
    reproducible behavior, be sure to set each element of the array before
    reading.

    Examples
    --------
    >>> import numpy as np
    >>> np.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 = np.ma.masked_all((3, 3))
    >>> a.dtype
    dtype('float64')
    >>> a = np.ma.masked_all((3, 3), dtype=np.int32)
    >>> a.dtype
    dtype('int32')

    mask)rG   npemptyrI   rD   )shapedtypeas      rQ   r    r    x   sF    p 	RXeU++'%)?)?@@	B 	B 	BAHrS   c                     t          j        |                               t                    }t          j        |j        t          |j                            |_        |S )aG  
    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.

    Notes
    -----
    Unlike other masked array creation functions (e.g. `numpy.ma.zeros_like`,
    `numpy.ma.ones_like`, `numpy.ma.full_like`), `masked_all_like` does not
    initialize the values of the array, and may therefore be marginally
    faster. However, the values stored in the newly allocated array are
    arbitrary. For reproducible behavior, be sure to set each element of the
    array before reading.

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

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

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

    r_   )	r\   
empty_likeviewr:   rI   r^   rD   r_   _mask)rV   r`   s     rQ   r!   r!      sI    v 	c,,Agag_QW%=%=>>>AGHrS   c                       fd}|S )a  
    Decorator to wrap a "_fromnxfunction" function, wrapping a numpy function as a
    masked array function, with proper docstring and name.

    Parameters
    ----------
    _fromnxfunction : ({params}) -> ndarray, {params}) -> masked_array
        Wrapper function that calls the wrapped numpy function

    Returns
    -------
    decorator : (f: ({params}) -> ndarray) -> ({params}) -> masked_array
        Function that accepts a numpy function and returns a masked array function

    c                      fd}t          j        | d           t          j         j        d          |_        |S )Nc                       g| R i |S N )argskwargs_fromnxfunctionnpfuncs     rQ   wrapperz<_fromnxfunction_function.<locals>.decorator.<locals>.wrapper
  s#    "?6;D;;;F;;;rS   )__name____qualname__)assignedzHThe function is applied to both the ``_data`` and the ``_mask``, if any.)	functoolsupdate_wrappermadoc_note__doc__)rn   ro   rm   s   ` rQ   	decoratorz+_fromnxfunction_function.<locals>.decorator	  s_    	< 	< 	< 	< 	< 	< 	 &;WXXXX+NV
 
 rS   rj   )rm   rx   s   ` rQ   _fromnxfunction_functionry      s$     	 	 	 	 	 rS   c                    t           | t          j        |          g|R i | | t          |          g|R i |          S )z
    Wraps a NumPy function that can be called with a single array argument followed by
    auxiliary args that are passed verbatim for both the data and mask calls.
    datar[   rG   r\   r<   rC   )rn   r`   rk   rl   s       rQ   _fromnxfunction_singler~     sc     VBJqMM3D333F33VLOO5d555f55   rS   c          	          t           | t          d |D                       g|R i | | t          d |D                       g|R i |          S )z
    Wraps a NumPy function that can be called with a single sequence of arrays followed
    by auxiliary args that are passed verbatim for both the data and mask calls.
    c              3   >   K   | ]}t          j        |          V  d S ri   )r\   r<   .0r`   s     rQ   	<genexpr>z&_fromnxfunction_seq.<locals>.<genexpr>*  s*      66A"*Q--666666rS   c              3   4   K   | ]}t          |          V  d S ri   )rC   r   s     rQ   r   z&_fromnxfunction_seq.<locals>.<genexpr>+  s(      88a,q//888888rS   r{   )rG   rN   )rn   arysrk   rl   s       rQ   _fromnxfunction_seqr   #  s     VE6666666HHHHHHVE88488888J4JJJ6JJ   rS   c                x     t           fd|D                       }t          |          dk    r|d         n|S )a  
    Wraps a NumPy function that can be called with multiple array arguments.
    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           	   3      K   | ]B}t           t          j        |          fi  t          |          fi            V  CdS )r{   Nr}   )r   r`   rl   rn   s     rQ   r   z*_fromnxfunction_allargs.<locals>.<genexpr>9  s        
 	 	
10000Q22622	
 	
 	
     rS   r7   r0   )rN   len)rn   r   rl   outs   ` ` rQ   _fromnxfunction_allargsr   .  s`          
     C XX]]3q66+rS   c                     d}|t          |           k    rTt          | |         d          r&| |         | ||dz   <   t          | |         d          &|dz  }|t          |           k    T| S )zFlatten a sequence in place.r0   __iter__r7   )r   hasattr)rP   ks     rQ   flatten_inplacer   T  sz    	AC==c!fj)) 	$ VC1q5	N c!fj)) 	$	Q C== JrS   c                 
   t          |dd          }|j        }t          ||          }dg|dz
  z  }t          j        |d          }t          t          |                    }|                    |           t          dd          ||<   t          j	        |j
                                      |          }	|                    ||            | |t          |                                                   g|R i |}
t          j        |
          }|s#	 t!          |
           n# t"          $ r d}Y nw xY wg }|ra|                    t          j	        |
          j                   t	          |	t(                    }|
|t          |          <   t          j        |	          }d}||k     r|dxx         dz  cc<   d}||         |	|         k    rA|d|z
  k    r8||dz
  xx         dz  cc<   d||<   |dz  }||         |	|         k    r	|d|z
  k    8|                    ||            | |t          |                                                   g|R i |}
|
|t          |          <   |                    t          |
          j                   |dz  }||k     n7t          |
dd          }
|                                }t          dd          g|
j        z  ||<   |                    ||           t          j        |	          }|	}t          |j
                  }	|
j
        |	|<   |                    t          |
          j                   t/          |	          }	t	          |	t(                    }|
|t          t/          |                                                    <   d}||k     r&|dxx         dz  cc<   d}||         ||         k    rA|d|z
  k    r8||dz
  xx         dz  cc<   d||<   |dz  }||         ||         k    r	|d|z
  k    8|                    ||           |                    ||            | |t          |                                                   g|R i |}
|
|t          t/          |                                                    <   |                    t          |
          j                   |dz  }||k     &t          j        t          j	        |                                                    }t3          |d	          st          j	        ||
          }n*t          ||
          }t5          j        |          |_        |S )z0
    (This docstring should be overwritten)
    FT)copysubokr0   r7   ONre   rb   )r1   ndimr5   r\   rK   rO   rangeremoveslicer<   r^   takeputrN   tolistisscalarr   	TypeErrorappendr_   objectprodr   r   maxr   ru   default_fill_value
fill_value)func1drW   rV   rk   rl   ndindiindlistoutshaperesasscalardtypesoutarrNtotr   nj	holdshape
max_dtypesresults                        rQ   r   r   ^  sC    %t
,
,
,C	Bb))D#a.C
SA599ooGNN4D$AdGz#)$$))'22HEE'3
&U188::&&'
9$
9
9
9&
9
9C{3H 	HHHH 	 	 	HHH	
 F .bjoo+,,,x(( uSzzwx  $hhGGGqLGGGAq6Xa[((qAF||AE


a


AQ q6Xa[((qAF|| EE'3&U188::../A$AAA&AAC!$F5::MM'#,,,---FA $hh Ce4000FFHH$%%&1$	gswx  		??gcll()))"8,,x((58u_QXXZZ00112$hhGGGqLGGGAq6Yq\))QVAE


a


AQ q6Yq\))QV EE'3EE'3&U188::../A$AAA&AAC9<F544556MM'#,,,---FA $hh "*V,,002233J3   :F*555z2221&99Ms   D& &D54D5c                 ,   t          |          }|j        }t          |          j        dk    r|f}|D ]_}|dk     r||z   }||f} | | }|j        |j        k    r|})t          j        ||          }|j        |j        k    r|}Qt          d          |S )z.
    (This docstring will be overwritten)
    r0   z7function is not returning an array of the correct shape)r<   r   r1   ru   expand_dims
ValueError)funcr`   axesvalNrW   rk   r   s           rQ   r   r     s     !**C	AT{{1w 9 9!88t8DT{dDk8sxCC.d++Cx38##  "8 9 9 9JrS   Notesa  

    Examples
    --------
    >>> import numpy as np
    >>> 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                    t                      t                     }t           j        d          |t          j        u ri }nd|i}|=  j        fi |}|j                             	                                        }nt          |          }	t           j        j        t          j        t          j        f          r!t	          j         j        |	j        d          }
nt	          j         j        |	j                  }
 j        |	j        k    rt          d          |	j        t!           fdD                       k    rt#          d          |	                    t	          j                            }	|	                    t!          fd	t+           j                  D                                 }	|t,          ur |	 j         z  }	|	xj         j        z  c_         |	j        d|
d
|} t	          j         |	|
          j        fi ||z  }|r@|j        |j        k    r,t	          j        ||j                                                  }||fS |S )aK  
    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 : None or int or tuple of ints, optional
        Axis or axes along which to average `a`.  The default,
        `axis=None`, will average over all of the elements of the input array.
        If axis is a tuple of ints, averaging is performed on all of the axes
        specified in the tuple instead of a single axis or all the axes as
        before.
    weights : array_like, optional
        An array of weights associated with the values in `a`. Each value in
        `a` contributes to the average according to its associated weight.
        The array of weights must be the same shape as `a` if no axis is
        specified, otherwise the weights must have dimensions and shape
        consistent with `a` along the specified axis.
        If `weights=None`, then all data in `a` are assumed to have a
        weight equal to one.
        The calculation is::

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

        where the sum is over all included elements.
        The only constraint on the values of `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`.

    Raises
    ------
    ZeroDivisionError
        When all weights along axis are zero. See `numpy.ma.average` for a
        version robust to this type of error.
    TypeError
        When `weights` does not have the same shape as `a`, and `axis=None`.
    ValueError
        When `weights` does not have dimensions and shape consistent with `a`
        along specified `axis`.

    Examples
    --------
    >>> import numpy as np
    >>> 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)
    >>> data = np.arange(8).reshape((2, 2, 2))
    >>> data
    array([[[0, 1],
            [2, 3]],
           [[4, 5],
            [6, 7]]])
    >>> np.ma.average(data, axis=(0, 1), weights=[[1./4, 3./4], [1., 1./2]])
    masked_array(data=[3.4, 4.4],
             mask=[False, False],
       fill_value=1e+20)
    >>> np.ma.average(data, axis=0, weights=[[1./4, 3./4], [1., 1./2]])
    Traceback (most recent call last):
        ...
    ValueError: Shape of weights must be consistent
    with shape of a along specified axis.

    >>> 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)
    NrW   )argnamer   f8z;Axis must be specified when shapes of a and weights differ.c              3   2   K   | ]}j         |         V  d S ri   )r^   )r   axr`   s     rQ   r   zaverage.<locals>.<genexpr>  s)      !=!="!'"+!=!=!=!=!=!=rS   zIShape of weights must be consistent with shape of a along specified axis.c              3   .   K   | ]\  }}|v r|nd V  dS )r7   Nrj   )r   r   srW   s      rQ   r   zaverage.<locals>.<genexpr>  sO       $E $E(-A +-**QQ! $E $E $E $E $E $ErS   )rW   r_   rb   rj   )r<   rB   r6   r   r\   _NoValuemeanr_   typer>   
issubclassintegerboolresult_typer^   r   rN   r   	transposeargsortreshape	enumeraterH   r[   rU   multiplybroadcast_tor   )r`   rW   weightsreturnedr   rX   keepdims_kwavgsclwgtresult_dtypes   ``         rQ   r   r     s   b 	

A

A#D!&&AAA2;!8,afT))[))innQWWT]]++gaglRZ$9:: 	>>!'39dCCLL>!'39==L 7ci|   yE!=!=!=!=!=!=!===== 78 8 8
 --
4 0 011C++e $E $E $E $E1:171C1C$E $E $E E E F FC F??!&/CHHHHcgC4|CC{CC2bk!S ,. . ..1$G G:EG GILM  9	!!/#sy116688CCx
rS   c                    t          | d          s`t          j        t          | d          ||||          }t	          |t          j                  rd|j        k    rt          |d          S |S t          | t          ||||          S )	a7	  
    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.

    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
    --------
    >>> import numpy as np
    >>> 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[   Tr   )rW   r   overwrite_inputr   r7   Fr   )r   r   rW   r   r   )
r   r\   r"   rA   rM   r2   r   rG   r3   _median)r`   rW   r   r   r   rX   s         rQ   r"   r"     s    B 1f Igat,,,4') ) ) a$$ 	af....HAGhTs$35 5 5 5rS   c                    t          j        | j        t           j                  rt           j        }nd }|rG+|                                                     |           n,|                     |           | nt          | |          dnt          j                  j	                 dk    rbt          d           gj        z  }t          dd          |<   t          |          }t           j                            |         |          S j        dk    r(t          t                    d          \  }}||z   dz
  |dz            }t          j        j        t           j                  rbj        dk    rW|                    |          }	|st          j        |	dd	|
          }	t           j        j                            |	          }	n|                    |          }	t           j                            |	          r8t          j        j                  st           j                                      S |	S t          d          }
|
dz  }|
dz  dk    }t          j        |||dz
            }t          j        ||g          }t          j        |          }fd} ||           t          j        j        t           j                  rkt           j                            ||          }	t          j        |	j        dd|	j        
           t           j        j                            |	          }	n"t           j                            ||          }	|	S )N)r   )rW   r   r0   )rW   r   r7      )r   g       @safe)castingr   TrW   r   rW   c                     t           j                            |           rXt          j        j        d           | j        z  }t           j                                      | j        |<   d| j        |<   d S d S )NTr   F)r\   ru   	is_maskedallr[   minimum_fill_valuer|   )r   repasortedrW   s     rQ   replace_maskedz_median.<locals>.replace_masked1  sq    
 5??1 	 F7<dTBBBBafLC%227;;AF3KAF3KKK	  	 rS   unsafe)r\   
issubdtyper_   inexactinfravelrJ   r5   r   r^   r   rN   ru   r   divmodr>   sizerU   true_dividelib_utils_impl_median_nancheckr   r   r[   r   wherer=   take_along_axisr|   )r`   rW   r   r   r   indexeridxoddmidr   countshllhlow_highr   r   s    `              @rQ   r   r     sL    
}QWbj)) V


 <<ggiiGLLJL////FFF444GGqt
;;;|#D',77}Ta ;;-',.a..uzz''*3z???|q%..!,,ScCi!mC!G+,=
33 	"q8H8HC  A CN1b&cBBB"33GQEEAAS!!A
 5??1 	5bfW\&:&: 	55++G4447555F!A 1*/C
aQA	AT	*	*	*B !'2D999H            N8	}W]BJ// 5EIIhTsI33
qvr8@@@@F//DAAEJJxdJ44HrS   c           
      \   t          |           } t          |           }|"t          t          | j                            }nt          || j                  }|t          u s|                                s| j        S |	                                rt          g           S | j        }|D ]}t          t          t          |                    t          t          |dz   | j                            z             }|t          d          f|z  |                    |           fz            }|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.

    Examples
    --------
    >>> import numpy as np
    >>> arr = [[1, 2], [3, 4]]
    >>> mask = [[0, 1], [0, 0]]
    >>> x = np.ma.array(arr, mask=mask)
    >>> np.ma.compress_nd(x, axis=0)
    array([[3, 4]])
    >>> np.ma.compress_nd(x, axis=1)
    array([[1],
           [3]])
    >>> np.ma.compress_nd(x)
    array([[3]])

    Nr7   r   )r<   rB   rN   r   r   r6   rH   any_datar   nxarrayrO   r   )xrW   rX   r|   r   r   s         rQ   r   r   I  s   H 	

A

A|U16]]###D!&11 	F{{!%%''{wuuww r{{7D @ @T%))__tE"q&!&,A,A'B'BBCCU4[[NR'AEEtE,<,<+<*>>?KrS   c                 r    t          |           j        dk    rt          d          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
    --------
    >>> import numpy as np
    >>> 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   )r<   r   NotImplementedErrorr   )r  rW   s     rQ   r   r     s:    f qzz!!"NOOOqt$$$$rS   c                 t    t          |           } | j        dk    rt          d          t          | d          S )ay  
    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.

    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.

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

    See Also
    --------
    compress_rowcols

    Examples
    --------
    >>> import numpy as np
    >>> a = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
    ...                                                   [1, 0, 0],
    ...                                                   [0, 0, 0]])
    >>> np.ma.compress_rows(a)
    array([[6, 7, 8]])

    r   z'compress_rows works for 2D arrays only.r0   r<   r   r  r   r`   s    rQ   r   r     s:    B 	

Av{{!"KLLLAq!!!rS   c                 t    t          |           } | j        dk    rt          d          t          | d          S )a  
    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.

    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.

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

    See Also
    --------
    compress_rowcols

    Examples
    --------
    >>> import numpy as np
    >>> a = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
    ...                                                   [1, 0, 0],
    ...                                                   [0, 0, 0]])
    >>> np.ma.compress_cols(a)
    array([[1, 2],
           [4, 5],
           [7, 8]])

    r   z'compress_cols works for 2D arrays only.r7   r	  r
  s    rQ   r   r     s:    F 	

Av{{!"KLLLAq!!!rS   c                    t          | d          } | j        dk    rt          d          t          |           }|t          u s|                                s| S |                                }| j                                        | _        |s"t          | t          j        |d                   <   |dv r&t          | ddt          j        |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 as np
    >>> a = np.zeros((3, 3), dtype=int)
    >>> a[1, 1] = 1
    >>> a
    array([[0, 0, 0],
           [0, 1, 0],
           [0, 0, 0]])
    >>> a = np.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)
    >>> np.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   )Nr7   r   Nr7   )r1   r   r  rB   rH   r  nonzerore   r   rF   r\   r,   )r`   rW   rX   	maskedvals       rQ   r   r     s    R 	auAv{{!"JKKK

AF{{!%%''{		IgllnnAG ,%+")IaL
!
!"}(.!!!RYy|$$
$%HrS   c                 v    |t           j        urt          j        dt          d           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 as np
    >>> a = np.zeros((3, 3), dtype=int)
    >>> a[1, 1] = 1
    >>> a
    array([[0, 0, 0],
           [0, 1, 0],
           [0, 0, 0]])
    >>> a = np.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)

    >>> np.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`   rW   s     rQ   r   r   d  sM    T 2; 	#$61	F 	F 	F 	F 1rS   c                 v    |t           j        urt          j        dt          d           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 as np
    >>> a = np.zeros((3, 3), dtype=int)
    >>> a[1, 1] = 1
    >>> a
    array([[0, 0, 0],
           [0, 1, 0],
           [0, 0, 0]])
    >>> a = np.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)
    >>> np.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)

    r  r   r  r7   r  r  s     rQ   r   r     sM    R 2; 	#$61	F 	F 	F 	F 1rS   c                 
   t          j        |           j        } | dd         | dd         z
  }|g}||                    d|           ||                    |           t          |          dk    rt          |          }|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.

    Examples
    --------
    >>> import numpy as np
    >>> arr = np.ma.array([1, 2, 4, 7, 0])
    >>> np.ma.ediff1d(arr)
    masked_array(data=[ 1,  2,  3, -7],
                 mask=False,
           fill_value=999999)

    r7   Nr   r0   )ru   
asanyarrayflatinsertr   r   r   )rV   to_endto_beginedarrayss        rQ   r   r     s    * -


!C	QRR3ss8	BTFa"""f
6{{a F^^IrS   c                    t          j        | ||          }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 as np
    >>> a = [1, 2, 1000, 2, 3]
    >>> mask = [0, 0, 1, 0, 0]
    >>> masked_a = np.ma.masked_array(a, mask)
    >>> masked_a
    masked_array(data=[1, 2, --, 2, 3],
                mask=[False, False,  True, False, False],
        fill_value=999999)
    >>> np.ma.unique(masked_a)
    masked_array(data=[1, 2, 3, --],
                mask=[False, False, False,  True],
        fill_value=999999)
    >>> np.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]))
    >>> np.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]))
    >>> np.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,   rM   rN   rO   rd   r:   )ar1r"  r#  outputs       rQ   r,   r,     s~    L Ys$0&46 6 6F &%   *f1INN;//q	v[))MrS   c                    |rt          j        | |f          }n0t          j        t          |           t          |          f          }|                                 |dd         |dd         |dd         k             S )aY  
    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
    --------
    >>> import numpy as np
    >>> 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   r7   )ru   r=   r,   rJ   )r$  ar2assume_uniqueauxs       rQ   r   r   %  sx    0  9nc3Z(( nfSkk6#;;788HHJJJss8CGs3B3x'((rS   c                 r   |st          |           } t          |          }t          j        | |fd          }|j        dk    r|S |                                 |                                }t          j        dg|dd         |dd         k    dgf          }|dd         |dd         k    }||         S )a  
    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.

    Examples
    --------
    >>> import numpy as np
    >>> ar1 = np.ma.array([1, 2, 3, 2, 4])
    >>> ar2 = np.ma.array([2, 3, 5, 7, 5])
    >>> np.ma.setxor1d(ar1, ar2)
    masked_array(data=[1, 4, 5, 7],
                 mask=False,
           fill_value=999999)

    Nr   r0   Tr7   r   )r,   ru   r=   r   rJ   r?   )r$  r'  r(  r)  auxfflagflag2s          rQ   r*   r*   F  s    *  SkkSkk
.#s$
/
/
/C
x1}}
HHJJJ::<<D>D6DHSbS	$9TFCDDD!""Xcrc"Eu:rS   c                    |s#t          | d          \  } }t          |          }t          j        | |f          }|                    d          }||         }|r|dd         |dd         k    }n|dd         |dd         k    }t          j        ||gf          }	|                    d          dt	          |                    }
|r|	|
         S |	|
         |         S )a3  
    Test whether each element of an array is also present in a second
    array.

    The output is always a masked array.

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

    See Also
    --------
    isin       : Version of this function that preserves the shape of ar1.

    Examples
    --------
    >>> import numpy as np
    >>> ar1 = np.ma.array([0, 1, 2, 5, 0])
    >>> ar2 = [0, 2]
    >>> np.ma.in1d(ar1, ar2)
    masked_array(data=[ True, False,  True, False,  True],
                 mask=False,
           fill_value=True)

    T)r#  	mergesort)kindr7   Nr   )r,   ru   r=   r   r   )r$  r'  r(  invertrev_idxarordersarbool_arr,  indxs              rQ   r   r   k  s    0  c$777WSkk	c
	#	#B JJKJ((E
U)C (qrr7c#2#h&qrr7c#2#h&>7VH-..D==k=**9CHH95D #DzDz'""rS   c                     t          j        |           } t          | |||                              | j                  S )aw  
    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.

    Examples
    --------
    >>> import numpy as np
    >>> element = np.ma.array([1, 2, 3, 4, 5, 6])
    >>> test_elements = [0, 2]
    >>> np.ma.isin(element, test_elements)
    masked_array(data=[False,  True, False, False, False, False],
                 mask=False,
           fill_value=True)

    r(  r1  )ru   r<   r   r   r^   )elementtest_elementsr(  r1  s       rQ   r   r     sB    0 j!!Gm  &ww}556rS   c                 L    t          t          j        | |fd                    S )a  
    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.

    Examples
    --------
    >>> import numpy as np
    >>> ar1 = np.ma.array([1, 2, 3, 4])
    >>> ar2 = np.ma.array([3, 4, 5, 6])
    >>> np.ma.union1d(ar1, ar2)
    masked_array(data=[1, 2, 3, 4, 5, 6],
             mask=False,
       fill_value=999999)

    Nr   )r,   ru   r=   )r$  r'  s     rQ   r-   r-     s%    * ".#s$777888rS   c                     |r't          j        |                                           } nt          |           } t          |          }| t	          | |dd                   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
    --------
    >>> import numpy as np
    >>> 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)

    Tr9  )ru   r<   r   r,   r   )r$  r'  r(  s      rQ   r)   r)     sY    *  joo##%%SkkSkktCD>>>??rS   Tc                    t          j        | ddt                    } t          j        |           }|s#|                                rt          d          | j        d         dk    rd}t          t          |                    }d|z
  }|rt          d          df}ndt          d          f}|d| j        d         dk    s| j        d         dk    rt          j        }nt          j        }t          j        |                              |          }nUt          |d	dt          
          }t          j        |          }	|s#|	                                rt          d          |                                s|	                                rN|j        | j        k    r>t          j        ||	          }
|
t           ur |
x}x| _        x|_        }	d	| _        d	|_        t          j        | |f|          } | j        d         dk    s| j        d         dk    rt          j        }nt          j        }t          j        t          j        ||	f|                                        |          }| |                     |          |         z  } | ||fS )z_
    Private function for the computation of covariance and correlation
    coefficients.

    r   T)ndminr   r_   zCannot process masked data.r0   r7   Ni   F)r   r?  r_   r   )ru   r1   floatrC   r  r   r^   intr   r   r\   float64float32logical_notastype
logical_orrH   re   _sharedmaskr=   r   )r  yrowvarallow_maskedxmaskrW   tup	xnm_dtypexnotmaskymaskcommon_masks              rQ   
_covhelperrQ    sc    	!$e444AOAE 8EIIKK 86777wqzQfFv:D "T{{D!U4[[!y 71:171:#7#7
II
I>%((//	::!%q666"" 	<		 	<:;;;99;; 	*%))++ 	*w!'!! mE599f,,8CCECAGCag$)AM$)AMNAq64(( 71:171:#7#7
II
I>".%"F"FGGNN
 
 V		S	!!Ax  rS   c                    |"|t          |          k    rt          d          ||rd}nd}t          | |||          \  } }}|st          j        |j        |          |z
  }t          j        |dt                    }t          j        dd          5  t          j        t          | j        d          t          | 
                                d                    |z  }	ddd           n# 1 swxY w Y   t          j        |	|                                          }
nt          j        ||j                  |z
  }t          j        |dt                    }t          j        dd          5  t          j        t          | d          t          | j        
                                d                    |z  }	ddd           n# 1 swxY w Y   t          j        |	|                                          }
|
S )	aA
  
    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``.

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

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

    Examples
    --------
    >>> import numpy as np
    >>> x = np.ma.array([[0, 1], [1, 1]], mask=[0, 1, 0, 1])
    >>> y = np.ma.array([[1, 0], [0, 1]], mask=[0, 0, 1, 1])
    >>> np.ma.cov(x, y)
    masked_array(
    data=[[--, --, --, --],
          [--, --, --, --],
          [--, --, --, --],
          [--, --, --, --]],
    mask=[[ True,  True,  True,  True],
          [ True,  True,  True,  True],
          [ True,  True,  True,  True],
          [ True,  True,  True,  True]],
    fill_value=1e+20,
    dtype=float64)

    Nzddof must be an integerr0   r7   rb   ignore)divideinvalidrZ   )rA  r   rQ  r\   r   T
less_equalr   errstater?   conjru   r1   squeeze)r  rH  rI  biasrJ  ddofrN  factr[   r|   r   s              rQ   r   r   ,  sb   L DCII--2333| 	DDD&q!V\BBQ& 5vhj(++d2}T1D111[(;;; 	F 	F6&a..&1*=*=>>ED	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F$T***2244vh
++d2}T1D111[(;;; 	F 	F6&A,,qsxxzz1(=(=>>ED	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F$T***2244Ms&   AC--C14C10AGGGc                    t          | |||          }	 t          j        t          j        |                    }n## t          $ r t          j                    cY S w xY w|t          j                            ||          z  }|S )an  
    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.
    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.

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

    Examples
    --------
    >>> import numpy as np
    >>> x = np.ma.array([[0, 1], [1, 1]], mask=[0, 1, 0, 1])
    >>> np.ma.corrcoef(x)
    masked_array(
      data=[[--, --],
            [--, --]],
      mask=[[ True,  True],
            [ True,  True]],
      fill_value=1e+20,
      dtype=float64)

    )rJ  )r   ru   sqrtdiagonalr   MaskedConstantr   outer)r  rH  rI  rJ  corrstds         rQ   r   r     s    ` q!V,777D#gbk$''(( # # # """""#BKc3'''DKs   &< AAc                   V     e Zd ZdZdZ ee          Ze fd            Z fdZ	 xZ
S )MAxisConcatenatorz
    Translate slice objects to concatenation along an axis.

    For documentation on usage, see `mr_class`.

    See Also
    --------
    mr_class

    rj   c                     t                                          |j        d          }t          ||j                  S )NFr   rZ   )supermakematr|   r1   r[   )clsrV   r|   	__class__s      rQ   ri  zMAxisConcatenator.makemat  s5     wwsxe44T))))rS   c                     t          |t                    rt          d          t                                          |          S )NzUnavailable for masked array.)rM   strr9   rh  __getitem__)selfkeyrk  s     rQ   rn  zMAxisConcatenator.__getitem__  s<    c3 	;9:::ww""3'''rS   )rp   
__module__rq   rw   	__slots__staticmethodr=   classmethodri  rn  __classcell__)rk  s   @rQ   rf  rf    s{        	 	 I,{++K* * * * [*( ( ( ( ( ( ( ( (rS   rf  c                       e Zd ZdZdZd ZdS )mr_classa~  
    Translate slice objects to concatenation along the first axis.

    This is the masked array version of `r_`.

    See Also
    --------
    r_

    Examples
    --------
    >>> import numpy as np
    >>> 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)

    rj   c                 <    t                               | d           d S )Nr0   )rf  __init__)ro  s    rQ   ry  zmr_class.__init__  s    ""4+++++rS   N)rp   rq  rq   rw   rr  ry  rj   rS   rQ   rw  rw    s4         $ I, , , , ,rS   rw  c              #      K   t          t          j        |           t          |           j                  D ]\  }}|s|V  |s|d         t
          fV   dS )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
    --------
    >>> import numpy as np
    >>> 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
    r0   N)zipr\   r$   rC   r  rF   )r`   
compresseditr[   s       rQ   r$   r$     ss      | q))<??+?@@    D 	 HHHH 	 Q%-	   rS   c                     t          |           }|t          u st          j        |          st          j        d| j        dz
  g          S t          j        |           }t          |          dk    r
|ddg         S dS )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
    --------
    >>> import numpy as np
    >>> 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

    r0   r7   r   N)rB   rH   r\   r  r1   r   flatnonzeror   )r`   rX   unmaskeds      rQ   r   r   M  su    \ 	

AF{{"&)){xAFQJ(((~qb!!H
8}}qB  trS   c                    t          |           } | j        dk    rt          |           S t          |           }t	          t          j        | j                  t          j         |g| j        z                      t          fdt          | j                  D                       t          fdt          | j                  D                       gS )az  
    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
    --------
    >>> import numpy as np
    >>> 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])

    Nr7   rZ   c              3   r   K   | ]1}|                                                                        V  2d S ri   )minr|  r   r   rW   r   s     rQ   r   z"notmasked_edges.<locals>.<genexpr>  ?      GGA#a&**T""--//GGGGGGrS   c              3   r   K   | ]1}|                                                                        V  2d S ri   )r   r|  r  s     rQ   r   z"notmasked_edges.<locals>.<genexpr>  r  rS   )
r<   r   r   rC   r1   r\   indicesr^   rN   r   )r`   rW   rX   r   s    ` @rQ   r&   r&     s    V 	

A|qv{{"1%%%QA

17##"*aS16\*B*B
C
C
CCGGGGGqvGGGGGGGGGGqvGGGGGK KrS   c                 T   t          |           }|t          u rt          d| j                  gS d}g }t	          j        |                                          D ]N\  }}t          t          |                    }|s&|	                    t          |||z                        ||z  }O|S )an  
    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).

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

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

    Examples
    --------
    >>> import numpy as np
    >>> 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   )
rB   rH   r   r   	itertoolsgroupbyr   r   rO   r   )r`   rX   r   r   r   gr   s          rQ   r   r     s    T 	

AF{{a  !!	AF#AGGII..  AQLL 	+MM%1q5//***	QMrS   c           	      z   t          |           } | j        }|dk    rt          d          ||dk    rt          |           S g }|dz   dz  }ddg}t	          dd          ||<   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
    --------
    >>> import numpy as np
    >>> 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.Nr7   r0   )	r<   r   r  r   r   r   r^   r   rN   )r`   rW   r   r   otherr   r   s          rQ   r%   r%     s    v 	

A	
B	Avv!"JKKK|rQww'***FAXNEa&CdD!!CI175>"" ? ?E
.qs}==>>>>MrS   c           
         | j         dk    r|                                 } | dd         | dd         z                                  }|d         dz   }| d         rt          |          dk    rt	          d| j                  gS t	          d|d                   g}|                    d t          |ddd         |ddd                   D                        nAt          |          dk    rg S d t          |ddd         |ddd                   D             }| d         r.|                    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.
    r7   Nr   r0   c              3   <   K   | ]\  }}t          ||          V  d S ri   r   r   leftrights      rQ   r   z_ezclump.<locals>.<genexpr>N  sL       B B!dE e$$ B B B B B BrS   r   c                 4    g | ]\  }}t          ||          S rj   r  r  s      rQ   
<listcomp>z_ezclump.<locals>.<listcomp>T  s&    NNNKD%U4NNNrS   )	r   r   r  r   r   r   extendr{  r   )r[   r   rs      rQ   _ezclumpr  >  sn    y1}}zz||8d3B3i
(
(
*
*C
a&1*CAw Os88q==!TY''((1c!f	 B B%(Qr!Vc!$Q$i%@%@B B B 	C 	C 	C 	C s88q==INN3s5Bq5z3qt!t93M3MNNNBx ,	s2w	**+++HrS   c                     t          | dt                    }|t          u rt          d| j                  gS t	          |           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`.

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

    Examples
    --------
    >>> import numpy as np
    >>> 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)]

    re   r0   )getattrrH   r   r   r  r`   r[   s     rQ   r	   r	   [  sA    < 1gv&&Dv~~a  !!TE??rS   c                 ^    t          j        |           }|t          u rg S t          |          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`.

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

    Examples
    --------
    >>> import numpy as np
    >>> 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)]

    )ru   rB   rH   r  r  s     rQ   r   r     s+    < :a==Dv~~	D>>rS   c                 j    t          j        | |          }t          |           }|t          urd||<   |S )zD
    Masked values in the input array result in rows of zeros.

    r0   )r\   r.   rB   rH   )r  r   _vanderrX   s       rQ   r.   r.     s5    
 i1ooG

A
NrS   c           	         t          |           } t          |          }t          |           }|j        dk    rt          |t          |                    }nZ|j        dk    r@t          t	          |                    }|t
          urt          ||dddf                   }nt          d          |qt          |          }|j        dk    rt          d          |j        d         |j        d         k    rt          d          t          |t          |                    }|t
          ur3| }	|||	         }t          j	        | |	         ||	         |||||          S t          j	        | ||||||          S )zE
    Any masked values in x is propagated in y, and vice-versa.

    r7   r   Nr0   z 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)
r<   rB   r   rE   r   rH   r   r^   r\   r'   )
r  rH  degrcondfullwr   rX   mynot_ms
             rQ   r'   r'     s^   
 	

A

A

Av{{Awqzz""	
1Yq\\""V2aaad8$$A:;;;}AJJ6Q;;>???71:##FGGGAwqzz""=%Az!E(AeHc5$3GGGz!QUD!S999rS   ri   )NNF)NNFF)NN)FF)F)NTT)NTFTN)T)NFNF)erw   __all__rs   r  r  numpyr\   r1   r  r2   numpy.lib._function_base_implr3   numpy.lib._index_tricks_implr4   numpy.lib.array_utilsr5   r6    r8   ru   r9   r:   r;   r<   r=   r>   r   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rR   r   r@  r    r!   ry   r~   r   r   r   r   r   r/   r(   r   r
   r   r+   r   r   r   r   r   findrstripr   r   r"   r   r   r   r   r   r   r   r   r   r,   r   r*   r   r   r-   r)   rQ  r   r   rf  rw  r#   r$   r   r&   r   r%   r  r	   r   r.   rv   r'   rj   rS   rQ   <module>r     s   
 
 
              + + + + + + + + 2 2 2 2 2 2 9 9 9 9 9 9 L L L L L L L L                                                   23 3 33 3 3 3l " : : : :z= = =H  <       , , ,( %$R]33
$$R]33
$$R]33
((33 3		RY	'	'""2?33		RY	'	'BH%%				*	*!!"+..  O O Od .6    2 & 081		#	(	(	1	11339688,.Obe[e e e e ePK5 K5 K5 K5\R R R Rj7 7 7 7t5% 5% 5% 5%p$" $" $"N&" &" &"RV V V Vr k 0 0 0 0f k / / / /l# # # #L/ / / /d) ) ) )B" " " "J,# ,# ,# ,#^6 6 6 6:9 9 90@ @ @ @D8! 8! 8! 8!v\ \ \ \~7 7 7 7z( ( ( ( (( ( ( (@, , , , ,  , , ,2 hjjB  B  B  B J5 5 5p1K 1K 1K 1Kh4 4 4nK K K K\  :! ! !H! ! !R	 	 	 	 RY.?? :  :  :  :F "+bj0'/BBrS   