
    9=e                      T    d dl Zd dlmZ d dlmZmZ ddlmZ d d dddZ	ddd
dZ
dS )    N)normalize_axis_index)_nan_allsame_contains_nan   )_chk_asarrayFaxisddofkeepdimsc                
   t          j        |           }|                    |d          }t          j        || j                  }|| dk    z                      |d          | z  }| j        |         t          j        t          j        ||          |          z
  }||k    }	||k    }
t          | |d          }|                                 }d||<   t          j	        ||d          }d|t          j        |	|j                  |
z  <   t          j
        d          5  t          j        |||d          }d	d	d	           n# 1 swxY w Y   ~t          j        | |d          dk    }d||<   ||z  }t           j        || |z  <   | |
z  }t          j        ||                   t           j        z  ||<   ||z  |	z  |
|z  z  }t           j        ||<   |s)t          j        ||          }|j        d
k    r|d
         }|S )z
    Private version of `variation` that ignores nan.

    `a` must be a numpy array.
    `axis` is assumed to be normalized, i.e. 0 <= axis < a.ndim.
    T)r	   r   r   r	   g      ?ignore)invalidr   N )npisnanallbroadcast_toshapeexpand_dimscount_nonzeror   copynanmeanerrstatenanstdnansuminfsignnansqueeze)ar	   r
   r   a_isnanall_nanall_nan_fullall_zerongoodddof_too_bigddof_equal_nis_consta2mean_astd_asum_zeroresultsigned_inf_masknan_masks                      6lib/python3.11/site-packages/scipy/stats/_variation.py_nanvariationr2      sp   : hqkkGkktdk33G?7AG44L16"''TD'AAWHLH WT]^B,W4@@@$GGHE %<L 5=LAD4888H	
B B|Z555F
 BEBr|RX..=>	X	&	&	& C C	"4dTBBBC C C C C C C C C C C C C C C
y555:H F8 V^F $&6FH9x i,.O gf_&=>>GF?'!L0L84KLHvF8  F...<2BZFMs   "EEE	propagater   c                   t          | |          \  } }t          || j                  }| j        |         }t	          | |          \  }}|r|dk    rt          | |||          S | j        dk    s||k    rat          | j                  }|rd||<   n||= t          |          dk    rt          j
        }n t          j        |t          j
                  }|S |                     |d          }	||k    r|                     |dd          }
t          j        |
t          j
                  }t          j        |	          t          j        z  j        |j        |
j        dk    <   |j        d	k    r|d	         }|S t          j        d
d
          5  |                     ||d          }
|
|	z  }ddd           n# 1 swxY w Y   |s)t          j        ||          }|j        d	k    r|d	         }|S )am  
    Compute the coefficient of variation.

    The coefficient of variation is the standard deviation divided by the
    mean.  This function is equivalent to::

        np.std(x, axis=axis, ddof=ddof) / np.mean(x)

    The default for ``ddof`` is 0, but many definitions of the coefficient
    of variation use the square root of the unbiased sample variance
    for the sample standard deviation, which corresponds to ``ddof=1``.

    The function does not take the absolute value of the mean of the data,
    so the return value is negative if the mean is negative.

    Parameters
    ----------
    a : array_like
        Input array.
    axis : int or None, optional
        Axis along which to calculate the coefficient of variation.
        Default is 0. If None, compute over the whole array `a`.
    nan_policy : {'propagate', 'raise', 'omit'}, optional
        Defines how to handle when input contains ``nan``.
        The following options are available:

          * 'propagate': return ``nan``
          * 'raise': raise an exception
          * 'omit': perform the calculation with ``nan`` values omitted

        The default is 'propagate'.
    ddof : int, optional
        Gives the "Delta Degrees Of Freedom" used when computing the
        standard deviation.  The divisor used in the calculation of the
        standard deviation is ``N - ddof``, where ``N`` is the number of
        elements.  `ddof` must be less than ``N``; if it isn't, the result
        will be ``nan`` or ``inf``, depending on ``N`` and the values in
        the array.  By default `ddof` is zero for backwards compatibility,
        but it is recommended to use ``ddof=1`` to ensure that the sample
        standard deviation is computed as the square root of the unbiased
        sample variance.
    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
    -------
    variation : ndarray
        The calculated variation along the requested axis.

    Notes
    -----
    There are several edge cases that are handled without generating a
    warning:

    * If both the mean and the standard deviation are zero, ``nan``
      is returned.
    * If the mean is zero and the standard deviation is nonzero, ``inf``
      is returned.
    * If the input has length zero (either because the array has zero
      length, or all the input values are ``nan`` and ``nan_policy`` is
      ``'omit'``), ``nan`` is returned.
    * If the input contains ``inf``, ``nan`` is returned.

    References
    ----------
    .. [1] Zwillinger, D. and Kokoska, S. (2000). CRC Standard
       Probability and Statistics Tables and Formulae. Chapman & Hall: New
       York. 2000.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.stats import variation
    >>> variation([1, 2, 3, 4, 5], ddof=1)
    0.5270462766947299

    Compute the variation along a given dimension of an array that contains
    a few ``nan`` values:

    >>> x = np.array([[  10.0, np.nan, 11.0, 19.0, 23.0, 29.0, 98.0],
    ...               [  29.0,   30.0, 32.0, 33.0, 35.0, 56.0, 57.0],
    ...               [np.nan, np.nan, 12.0, 13.0, 16.0, 16.0, 17.0]])
    >>> variation(x, axis=1, ddof=1, nan_policy='omit')
    array([1.05109361, 0.31428986, 0.146483  ])

    )ndimomitr   r   r   )
fill_valueTr4   r   r   )divider   )r
   r   Nr   )r   r   r6   r   r   r2   sizelistlenr   r   fullmeanstd	full_liker   r   flatr   r    )r!   r	   
nan_policyr
   r   ncontains_nanshpr.   r+   r,   s              r1   	variationrF   [   s1   r 1d##GAt16222D	A,Q
;;L* I
f,,QTxHHHHv{{dQhh 17mm 	CIID	s88q==VFFWSRV444FVVD4V((Fqyy4a$77e777')wv'?&EEJN#<2BZF	Hh	7	7	7    d55                                F...<2BZFMs   F88F<?F<)r   r3   r   )numpyr   numpy.core.multiarrayr   scipy._lib._utilr   r   	_stats_pyr   r2   rF   r       r1   <module>rL      s        6 6 6 6 6 6 8 8 8 8 8 8 8 8 # # # # # # Q Q Q Q Q QhDU D D D D D D DrK   