/ lib / numpy / lib / nanfunctions.pyc
nanfunctions.pyc
   1  o

   2  [��cl�@sZdZddlZddlZddlZddlmZddlmZej	ej
   3  dd�Z
   4  gd�Zd[dd	�Zd
   5  d�Z
dd
�Zd\dd�Zd[dd�Z		d]dd�Ze
   6  e�ddejejejfdd��Z		d]dd�Ze
   7  e�ddejejejfdd��Zd^dd�dd�Ze
   8  e�d^ejd�dd��Zd^dd�d d!�Ze
   9  e�d^ejd�d"d#��Z		d_d$d%�Ze
  10  e�dddejejejfd&d'��Z		d_d(d)�Ze
  11  e�dddejejejfd*d+��Zd`d,d-�Ze
  12  e�d`d.d/��Zd`d0d1�Z e
  13  e �d`d2d3��Z!dadd4�d5d6�Z"e
  14  e"�dddejfejd4�d7d8��Z#d\d9d:�Z$dbd;d<�Z%dbd=d>�Z&	dad?d@�Z'e
  15  e'�dddejfdAdB��Z(		d]ddC�dDdE�Z)e
  16  e)�ddddFejfddC�dGdH��Z*		d]ddC�dIdJ�Z+e
  17  e+�ddddFejfddC�dKdL��Z,ddddFejfdMdN�Z-		FdcdOdP�Z.dddQdR�Z/		d]dd4�dSdT�Z0e
  18  e0�ddddejfejd4�dUdV��Z1		d]dd4�dWdX�Z2e
  19  e2�ddddejfejd4�dYdZ��Z3dS)ea�
  20  Functions that ignore NaN.
  21  
  22  Functions
  23  ---------
  24  
  25  - `nanmin` -- minimum non-NaN value
  26  - `nanmax` -- maximum non-NaN value
  27  - `nanargmin` -- index of minimum non-NaN value
  28  - `nanargmax` -- index of maximum non-NaN value
  29  - `nansum` -- sum of non-NaN values
  30  - `nanprod` -- product of non-NaN values
  31  - `nancumsum` -- cumulative sum of non-NaN values
  32  - `nancumprod` -- cumulative product of non-NaN values
  33  - `nanmean` -- mean of non-NaN values
  34  - `nanvar` -- variance of non-NaN values
  35  - `nanstd` -- standard deviation of non-NaN values
  36  - `nanmedian` -- median of non-NaN values
  37  - `nanquantile` -- qth quantile of non-NaN values
  38  - `nanpercentile` -- qth percentile of non-NaN values
  39  
  40  �N)�
function_base)�	overrides�numpy)�module)�nansum�nanmax�nanmin�	nanargmax�	nanargmin�nanmean�	nanmedian�
nanpercentile�nanvar�nanstd�nanprod�	nancumsum�
  41  nancumprod�nanquantilecCs0|jjdvrdStj||d�}tj||d�}|S)ap
  42      Parameters
  43      ----------
  44      a : array-like
  45          Input array with at least 1 dimension.
  46      out : ndarray, optional
  47          Alternate output array in which to place the result.  The default
  48          is ``None``; if provided, it must have the same shape as the
  49          expected output and will prevent the allocation of a new array.
  50  
  51      Returns
  52      -------
  53      y : bool ndarray or True
  54          A bool array where ``np.nan`` positions are marked with ``False``
  55          and other positions are marked with ``True``. If the type of ``a``
  56          is such that it can't possibly contain ``np.nan``, returns ``True``.
  57      �fcT��out)�dtype�kind�np�isnan�invert)�ar�y�r��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\numpy\lib\nanfunctions.py�	_nan_mask)s
  58  r cCsxt�|�}|jtjkrtj||td�}nt|jjtj�r"t�	|�}nd}|dur8tj
  59  |ddd�}tj|||d�||fS)a�
  60      If `a` is of inexact type, make a copy of `a`, replace NaNs with
  61      the `val` value, and return the copy together with a boolean mask
  62      marking the locations where NaNs were present. If `a` is not of
  63      inexact type, do nothing and return `a` together with a mask of None.
  64  
  65      Note that scalars will end up as array scalars, which is important
  66      for using the result as the value of the out argument in some
  67      operations.
  68  
  69      Parameters
  70      ----------
  71      a : array-like
  72          Input array.
  73      val : float
  74          NaN values are set to val before doing the operation.
  75  
  76      Returns
  77      -------
  78      y : ndarray
  79          If `a` is of inexact type, return a copy of `a` with the NaNs
  80          replaced by the fill value, otherwise return `a`.
  81      mask: {bool, None}
  82          If `a` is of inexact type, return a boolean mask marking locations of
  83          NaNs, otherwise return None.
  84  
  85      �rNT)�subok�copy��where)r�
  86  asanyarrayr�object_�	not_equal�bool�
  87  issubclass�type�inexactr�array�copyto�r�val�maskrrr�_replace_nanDs
  88  r2cCs2t|tj�rtj|||dd�|S|j�|�}|S)a\
  89      Replace values in `a` with NaN where `mask` is True.  This differs from
  90      copyto in that it will deal with the case where `a` is a numpy scalar.
  91  
  92      Parameters
  93      ----------
  94      a : ndarray or numpy scalar
  95          Array or numpy scalar some of whose values are to be replaced
  96          by val.
  97      val : numpy scalar
  98          Value used a replacement.
  99      mask : ndarray, scalar
 100          Boolean array. Where True the corresponding element of `a` is
 101          replaced by `val`. Broadcasts.
 102  
 103      Returns
 104      -------
 105      res : ndarray, scalar
 106          Array with elements replaced or scalar `val`.
 107  
 108      �unsafe)r%�casting)�
 109  isinstancer�ndarrayr.rr+r/rrr�_copytoqs
 110  �r7FcCs�|jtkrtj||td�}nt�|�}t�|�d}|j|jkr0tj	dt
 111  dd�|dd�dfS|jdkr9||fS|s?|��}||jd�||jd�}|||d|j�<|d|j�dfS)a�
 112      Equivalent to arr1d[~arr1d.isnan()], but in a different order
 113  
 114      Presumably faster as it incurs fewer copies
 115  
 116      Parameters
 117      ----------
 118      arr1d : ndarray
 119          Array to remove nans from
 120      overwrite_input : bool
 121          True if `arr1d` can be modified in place
 122  
 123      Returns
 124      -------
 125      res : ndarray
 126          Array with nan elements removed
 127      overwrite_input : bool
 128          True if `res` can be modified in place, given the constraint on the
 129          input
 130      r!r�All-NaN slice encountered���
 131  stacklevelNT)r�objectrr(r)r�nonzero�size�warnings�warn�RuntimeWarningr#)�arr1d�overwrite_input�c�sZenonanrrr�_remove_nan_1d�s 
 132  
 133  �
 134  "rFc	Cs�tjddd��dt|tj�r2|dur"tj|||dd�Wd�Stj|||dd�Wd�S|dur[z|j�||�WWd�StyZ||YWd�Swtj|||dd�Wd�S1snwYdS)a�
 135      Compute a/b ignoring invalid results. If `a` is an array the division
 136      is done in place. If `a` is a scalar, then its type is preserved in the
 137      output. If out is None, then a is used instead so that the division
 138      is in place. Note that this is only called with `a` an inexact type.
 139  
 140      Parameters
 141      ----------
 142      a : {ndarray, numpy scalar}
 143          Numerator. Expected to be of inexact type but not checked.
 144      b : {ndarray, numpy scalar}
 145          Denominator.
 146      out : ndarray, optional
 147          Alternate output array in which to place the result.  The default
 148          is ``None``; if provided, it must have the same shape as the
 149          expected output, but the type will be cast if necessary.
 150  
 151      Returns
 152      -------
 153      ret : {ndarray, numpy scalar}
 154          The return value is a/b. If `a` was an ndarray the division is done
 155          in place. If `a` is a numpy scalar, the division preserves its type.
 156  
 157      �ignore)�invalid�divideNr3)rr4)r�errstater5r6rIrr+�AttributeError)r�brrrr�_divide_by_count�s"���
 158  �$�rMcC�||fS�Nr�r�axisr�keepdims�initialr%rrr�_nanmin_dispatcher��rTc	Csi}|tjur||d<|tjur||d<|tjur||d<t|�tjurH|jtjkrHtjj|f||d�|��}t�|��	�rFt
 159  jdtdd�|St
|tj
 160  �\}}tj|f||d�|��}|durc|S|�dd�tj|fd	|i|��}t�	|�r�t|tj|�}t
 161  jd
 162  tdd�|S)a�
 163      Return minimum of an array or minimum along an axis, ignoring any NaNs.
 164      When all-NaN slices are encountered a ``RuntimeWarning`` is raised and
 165      Nan is returned for that slice.
 166  
 167      Parameters
 168      ----------
 169      a : array_like
 170          Array containing numbers whose minimum is desired. If `a` is not an
 171          array, a conversion is attempted.
 172      axis : {int, tuple of int, None}, optional
 173          Axis or axes along which the minimum is computed. The default is to compute
 174          the minimum of the flattened array.
 175      out : ndarray, optional
 176          Alternate output array in which to place the result.  The default
 177          is ``None``; if provided, it must have the same shape as the
 178          expected output, but the type will be cast if necessary. See
 179          :ref:`ufuncs-output-type` for more details.
 180  
 181          .. versionadded:: 1.8.0
 182      keepdims : bool, optional
 183          If this is set to True, the axes which are reduced are left
 184          in the result as dimensions with size one. With this option,
 185          the result will broadcast correctly against the original `a`.
 186  
 187          If the value is anything but the default, then
 188          `keepdims` will be passed through to the `min` method
 189          of sub-classes of `ndarray`.  If the sub-classes methods
 190          does not implement `keepdims` any exceptions will be raised.
 191  
 192          .. versionadded:: 1.8.0
 193      initial : scalar, optional
 194          The maximum value of an output element. Must be present to allow
 195          computation on empty slice. See `~numpy.ufunc.reduce` for details.
 196  
 197          .. versionadded:: 1.22.0
 198      where : array_like of bool, optional
 199          Elements to compare for the minimum. See `~numpy.ufunc.reduce`
 200          for details.
 201  
 202          .. versionadded:: 1.22.0
 203  
 204      Returns
 205      -------
 206      nanmin : ndarray
 207          An array with the same shape as `a`, with the specified axis
 208          removed.  If `a` is a 0-d array, or if axis is None, an ndarray
 209          scalar is returned.  The same dtype as `a` is returned.
 210  
 211      See Also
 212      --------
 213      nanmax :
 214          The maximum value of an array along a given axis, ignoring any NaNs.
 215      amin :
 216          The minimum value of an array along a given axis, propagating any NaNs.
 217      fmin :
 218          Element-wise minimum of two arrays, ignoring any NaNs.
 219      minimum :
 220          Element-wise minimum of two arrays, propagating any NaNs.
 221      isnan :
 222          Shows which elements are Not a Number (NaN).
 223      isfinite:
 224          Shows which elements are neither NaN nor infinity.
 225  
 226      amax, fmax, maximum
 227  
 228      Notes
 229      -----
 230      NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic
 231      (IEEE 754). This means that Not a Number is not equivalent to infinity.
 232      Positive infinity is treated as a very large number and negative
 233      infinity is treated as a very small (i.e. negative) number.
 234  
 235      If the input has a integer type the function is equivalent to np.min.
 236  
 237      Examples
 238      --------
 239      >>> a = np.array([[1, 2], [3, np.nan]])
 240      >>> np.nanmin(a)
 241      1.0
 242      >>> np.nanmin(a, axis=0)
 243      array([1.,  2.])
 244      >>> np.nanmin(a, axis=1)
 245      array([1.,  3.])
 246  
 247      When positive infinity and negative infinity are present:
 248  
 249      >>> np.nanmin([1, 2, np.nan, np.inf])
 250      1.0
 251      >>> np.nanmin([1, 2, np.nan, np.NINF])
 252      -inf
 253  
 254      rRrSr%�rQrr8�r:NrQ�All-NaN axis encountered)r�_NoValuer+r6rr'�fmin�reducer�anyr?r@rAr2�inf�amin�pop�allr7�nan�	rrQrrRrSr%�kwargs�resr1rrrr��4`
 255  
 256  
 257  ��
 258  �rcCrNrOrrPrrr�_nanmax_dispatcherlrUrfc	Csi}|tjur||d<|tjur||d<|tjur||d<t|�tjurH|jtjkrHtjj|f||d�|��}t�|��	�rFt
 259  jdtdd�|St
|tj�\}}tj|f||d�|��}|durc|S|�dd�tj|fd	|i|��}t�	|�r�t|tj|�}t
 260  jd
 261  tdd�|S)a�
 262      Return the maximum of an array or maximum along an axis, ignoring any
 263      NaNs.  When all-NaN slices are encountered a ``RuntimeWarning`` is
 264      raised and NaN is returned for that slice.
 265  
 266      Parameters
 267      ----------
 268      a : array_like
 269          Array containing numbers whose maximum is desired. If `a` is not an
 270          array, a conversion is attempted.
 271      axis : {int, tuple of int, None}, optional
 272          Axis or axes along which the maximum is computed. The default is to compute
 273          the maximum of the flattened array.
 274      out : ndarray, optional
 275          Alternate output array in which to place the result.  The default
 276          is ``None``; if provided, it must have the same shape as the
 277          expected output, but the type will be cast if necessary. See
 278          :ref:`ufuncs-output-type` for more details.
 279  
 280          .. versionadded:: 1.8.0
 281      keepdims : bool, optional
 282          If this is set to True, the axes which are reduced are left
 283          in the result as dimensions with size one. With this option,
 284          the result will broadcast correctly against the original `a`.
 285  
 286          If the value is anything but the default, then
 287          `keepdims` will be passed through to the `max` method
 288          of sub-classes of `ndarray`.  If the sub-classes methods
 289          does not implement `keepdims` any exceptions will be raised.
 290  
 291          .. versionadded:: 1.8.0
 292      initial : scalar, optional
 293          The minimum value of an output element. Must be present to allow
 294          computation on empty slice. See `~numpy.ufunc.reduce` for details.
 295  
 296          .. versionadded:: 1.22.0
 297      where : array_like of bool, optional
 298          Elements to compare for the maximum. See `~numpy.ufunc.reduce`
 299          for details.
 300  
 301          .. versionadded:: 1.22.0
 302  
 303      Returns
 304      -------
 305      nanmax : ndarray
 306          An array with the same shape as `a`, with the specified axis removed.
 307          If `a` is a 0-d array, or if axis is None, an ndarray scalar is
 308          returned.  The same dtype as `a` is returned.
 309  
 310      See Also
 311      --------
 312      nanmin :
 313          The minimum value of an array along a given axis, ignoring any NaNs.
 314      amax :
 315          The maximum value of an array along a given axis, propagating any NaNs.
 316      fmax :
 317          Element-wise maximum of two arrays, ignoring any NaNs.
 318      maximum :
 319          Element-wise maximum of two arrays, propagating any NaNs.
 320      isnan :
 321          Shows which elements are Not a Number (NaN).
 322      isfinite:
 323          Shows which elements are neither NaN nor infinity.
 324  
 325      amin, fmin, minimum
 326  
 327      Notes
 328      -----
 329      NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic
 330      (IEEE 754). This means that Not a Number is not equivalent to infinity.
 331      Positive infinity is treated as a very large number and negative
 332      infinity is treated as a very small (i.e. negative) number.
 333  
 334      If the input has a integer type the function is equivalent to np.max.
 335  
 336      Examples
 337      --------
 338      >>> a = np.array([[1, 2], [3, np.nan]])
 339      >>> np.nanmax(a)
 340      3.0
 341      >>> np.nanmax(a, axis=0)
 342      array([3.,  2.])
 343      >>> np.nanmax(a, axis=1)
 344      array([2.,  3.])
 345  
 346      When positive infinity and negative infinity are present:
 347  
 348      >>> np.nanmax([1, 2, np.nan, np.NINF])
 349      2.0
 350      >>> np.nanmax([1, 2, np.nan, np.inf])
 351      inf
 352  
 353      rRrSr%rVr8rWr:NrQrX)rrYr+r6rr'�fmaxr[rr\r?r@rAr2r]�amaxr_r`r7rarbrrrrqrer)rRcC�|fSrOr�rrQrrRrrr�_nanargmin_dispatcher��rkcCsNt|tj�\}}|durtj||d�}t�|�rtd��tj||||d�}|S)a�
 354      Return the indices of the minimum values in the specified axis ignoring
 355      NaNs. For all-NaN slices ``ValueError`` is raised. Warning: the results
 356      cannot be trusted if a slice contains only NaNs and Infs.
 357  
 358      Parameters
 359      ----------
 360      a : array_like
 361          Input data.
 362      axis : int, optional
 363          Axis along which to operate.  By default flattened input is used.
 364      out : array, optional
 365          If provided, the result will be inserted into this array. It should
 366          be of the appropriate shape and dtype.
 367  
 368          .. versionadded:: 1.22.0
 369      keepdims : bool, optional
 370          If this is set to True, the axes which are reduced are left
 371          in the result as dimensions with size one. With this option,
 372          the result will broadcast correctly against the array.
 373  
 374          .. versionadded:: 1.22.0
 375  
 376      Returns
 377      -------
 378      index_array : ndarray
 379          An array of indices or a single index value.
 380  
 381      See Also
 382      --------
 383      argmin, nanargmax
 384  
 385      Examples
 386      --------
 387      >>> a = np.array([[np.nan, 4], [2, 3]])
 388      >>> np.argmin(a)
 389      0
 390      >>> np.nanargmin(a)
 391      2
 392      >>> np.nanargmin(a, axis=0)
 393      array([1, 1])
 394      >>> np.nanargmin(a, axis=1)
 395      array([1, 0])
 396  
 397      N�rQr8�rQrrR)r2rr]r`r\�
 398  ValueError�argmin�rrQrrRr1rdrrrr
 399  �s/
 400  r
 401  cCrirOrrjrrr�_nanargmax_dispatcher-rlrrcCsPt|tj�\}}|durtj||d�}t�|�rtd��tj||||d�}|S)a�
 402      Return the indices of the maximum values in the specified axis ignoring
 403      NaNs. For all-NaN slices ``ValueError`` is raised. Warning: the
 404      results cannot be trusted if a slice contains only NaNs and -Infs.
 405  
 406  
 407      Parameters
 408      ----------
 409      a : array_like
 410          Input data.
 411      axis : int, optional
 412          Axis along which to operate.  By default flattened input is used.
 413      out : array, optional
 414          If provided, the result will be inserted into this array. It should
 415          be of the appropriate shape and dtype.
 416  
 417          .. versionadded:: 1.22.0
 418      keepdims : bool, optional
 419          If this is set to True, the axes which are reduced are left
 420          in the result as dimensions with size one. With this option,
 421          the result will broadcast correctly against the array.
 422  
 423          .. versionadded:: 1.22.0
 424  
 425      Returns
 426      -------
 427      index_array : ndarray
 428          An array of indices or a single index value.
 429  
 430      See Also
 431      --------
 432      argmax, nanargmin
 433  
 434      Examples
 435      --------
 436      >>> a = np.array([[np.nan, 4], [2, 3]])
 437      >>> np.argmax(a)
 438      0
 439      >>> np.nanargmax(a)
 440      1
 441      >>> np.nanargmax(a, axis=0)
 442      array([1, 0])
 443      >>> np.nanargmax(a, axis=1)
 444      array([1, 1])
 445  
 446      Nrmr8rn)r2rr]r`r\ro�argmaxrqrrrr	1s0
 447  r	cC�||fSrOr�rrQrrrRrSr%rrr�_nansum_dispatcherjrUrvc	C�&t|d�\}}tj|||||||d�S)aR

 448      Return the sum of array elements over a given axis treating Not a
 449      Numbers (NaNs) as zero.
 450  
 451      In NumPy versions <= 1.9.0 Nan is returned for slices that are all-NaN or
 452      empty. In later versions zero is returned.
 453  
 454      Parameters
 455      ----------
 456      a : array_like
 457          Array containing numbers whose sum is desired. If `a` is not an
 458          array, a conversion is attempted.
 459      axis : {int, tuple of int, None}, optional
 460          Axis or axes along which the sum is computed. The default is to compute the
 461          sum of the flattened array.
 462      dtype : data-type, optional
 463          The type of the returned array and of the accumulator in which the
 464          elements are summed.  By default, the dtype of `a` is used.  An
 465          exception is when `a` has an integer type with less precision than
 466          the platform (u)intp. In that case, the default will be either
 467          (u)int32 or (u)int64 depending on whether the platform is 32 or 64
 468          bits. For inexact inputs, dtype must be inexact.
 469  
 470          .. versionadded:: 1.8.0
 471      out : ndarray, optional
 472          Alternate output array in which to place the result.  The default
 473          is ``None``. If provided, it must have the same shape as the
 474          expected output, but the type will be cast if necessary.  See
 475          :ref:`ufuncs-output-type` for more details. The casting of NaN to integer
 476          can yield unexpected results.
 477  
 478          .. versionadded:: 1.8.0
 479      keepdims : bool, optional
 480          If this is set to True, the axes which are reduced are left
 481          in the result as dimensions with size one. With this option,
 482          the result will broadcast correctly against the original `a`.
 483  
 484  
 485          If the value is anything but the default, then
 486          `keepdims` will be passed through to the `mean` or `sum` methods
 487          of sub-classes of `ndarray`.  If the sub-classes methods
 488          does not implement `keepdims` any exceptions will be raised.
 489  
 490          .. versionadded:: 1.8.0
 491      initial : scalar, optional
 492          Starting value for the sum. See `~numpy.ufunc.reduce` for details.
 493  
 494          .. versionadded:: 1.22.0
 495      where : array_like of bool, optional
 496          Elements to include in the sum. See `~numpy.ufunc.reduce` for details.
 497  
 498          .. versionadded:: 1.22.0
 499  
 500      Returns
 501      -------
 502      nansum : ndarray.
 503          A new array holding the result is returned unless `out` is
 504          specified, in which it is returned. The result has the same
 505          size as `a`, and the same shape as `a` if `axis` is not None
 506          or `a` is a 1-d array.
 507  
 508      See Also
 509      --------
 510      numpy.sum : Sum across array propagating NaNs.
 511      isnan : Show which elements are NaN.
 512      isfinite : Show which elements are not NaN or +/-inf.
 513  
 514      Notes
 515      -----
 516      If both positive and negative infinity are present, the sum will be Not
 517      A Number (NaN).
 518  
 519      Examples
 520      --------
 521      >>> np.nansum(1)
 522      1
 523      >>> np.nansum([1])
 524      1
 525      >>> np.nansum([1, np.nan])
 526      1.0
 527      >>> a = np.array([[1, 1], [1, np.nan]])
 528      >>> np.nansum(a)
 529      3.0
 530      >>> np.nansum(a, axis=0)
 531      array([2.,  1.])
 532      >>> np.nansum([1, np.nan, np.inf])
 533      inf
 534      >>> np.nansum([1, np.nan, np.NINF])
 535      -inf
 536      >>> from numpy.testing import suppress_warnings
 537      >>> with suppress_warnings() as sup:
 538      ...     sup.filter(RuntimeWarning)
 539      ...     np.nansum([1, np.nan, np.inf, -np.inf]) # both +/- infinity present
 540      nan
 541  
 542      r�rQrrrRrSr%)r2r�sum�rrQrrrRrSr%r1rrrrosc�rcCrtrOrrurrr�_nanprod_dispatcher�rUr{c	Crw)a�	
 543      Return the product of array elements over a given axis treating Not a
 544      Numbers (NaNs) as ones.
 545  
 546      One is returned for slices that are all-NaN or empty.
 547  
 548      .. versionadded:: 1.10.0
 549  
 550      Parameters
 551      ----------
 552      a : array_like
 553          Array containing numbers whose product is desired. If `a` is not an
 554          array, a conversion is attempted.
 555      axis : {int, tuple of int, None}, optional
 556          Axis or axes along which the product is computed. The default is to compute
 557          the product of the flattened array.
 558      dtype : data-type, optional
 559          The type of the returned array and of the accumulator in which the
 560          elements are summed.  By default, the dtype of `a` is used.  An
 561          exception is when `a` has an integer type with less precision than
 562          the platform (u)intp. In that case, the default will be either
 563          (u)int32 or (u)int64 depending on whether the platform is 32 or 64
 564          bits. For inexact inputs, dtype must be inexact.
 565      out : ndarray, optional
 566          Alternate output array in which to place the result.  The default
 567          is ``None``. If provided, it must have the same shape as the
 568          expected output, but the type will be cast if necessary. See
 569          :ref:`ufuncs-output-type` for more details. The casting of NaN to integer
 570          can yield unexpected results.
 571      keepdims : bool, optional
 572          If True, the axes which are reduced are left in the result as
 573          dimensions with size one. With this option, the result will
 574          broadcast correctly against the original `arr`.
 575      initial : scalar, optional
 576          The starting value for this product. See `~numpy.ufunc.reduce`
 577          for details.
 578  
 579          .. versionadded:: 1.22.0
 580      where : array_like of bool, optional
 581          Elements to include in the product. See `~numpy.ufunc.reduce`
 582          for details.
 583  
 584          .. versionadded:: 1.22.0
 585  
 586      Returns
 587      -------
 588      nanprod : ndarray
 589          A new array holding the result is returned unless `out` is
 590          specified, in which case it is returned.
 591  
 592      See Also
 593      --------
 594      numpy.prod : Product across array propagating NaNs.
 595      isnan : Show which elements are NaN.
 596  
 597      Examples
 598      --------
 599      >>> np.nanprod(1)
 600      1
 601      >>> np.nanprod([1])
 602      1
 603      >>> np.nanprod([1, np.nan])
 604      1.0
 605      >>> a = np.array([[1, 2], [3, np.nan]])
 606      >>> np.nanprod(a)
 607      6.0
 608      >>> np.nanprod(a, axis=0)
 609      array([3., 2.])
 610  
 611      �rx)r2r�prodrzrrrr�sI�rcCrtrOr�rrQrrrrr�_nancumsum_dispatcher*�rcC� t|d�\}}tj||||d�S)a�
 612      Return the cumulative sum of array elements over a given axis treating Not a
 613      Numbers (NaNs) as zero.  The cumulative sum does not change when NaNs are
 614      encountered and leading NaNs are replaced by zeros.
 615  
 616      Zeros are returned for slices that are all-NaN or empty.
 617  
 618      .. versionadded:: 1.12.0
 619  
 620      Parameters
 621      ----------
 622      a : array_like
 623          Input array.
 624      axis : int, optional
 625          Axis along which the cumulative sum is computed. The default
 626          (None) is to compute the cumsum over the flattened array.
 627      dtype : dtype, optional
 628          Type of the returned array and of the accumulator in which the
 629          elements are summed.  If `dtype` is not specified, it defaults
 630          to the dtype of `a`, unless `a` has an integer dtype with a
 631          precision less than that of the default platform integer.  In
 632          that case, the default platform integer is used.
 633      out : ndarray, optional
 634          Alternative output array in which to place the result. It must
 635          have the same shape and buffer length as the expected output
 636          but the type will be cast if necessary. See :ref:`ufuncs-output-type` for
 637          more details.
 638  
 639      Returns
 640      -------
 641      nancumsum : ndarray.
 642          A new array holding the result is returned unless `out` is
 643          specified, in which it is returned. The result has the same
 644          size as `a`, and the same shape as `a` if `axis` is not None
 645          or `a` is a 1-d array.
 646  
 647      See Also
 648      --------
 649      numpy.cumsum : Cumulative sum across array propagating NaNs.
 650      isnan : Show which elements are NaN.
 651  
 652      Examples
 653      --------
 654      >>> np.nancumsum(1)
 655      array([1])
 656      >>> np.nancumsum([1])
 657      array([1])
 658      >>> np.nancumsum([1, np.nan])
 659      array([1.,  1.])
 660      >>> a = np.array([[1, 2], [3, np.nan]])
 661      >>> np.nancumsum(a)
 662      array([1.,  3.,  6.,  6.])
 663      >>> np.nancumsum(a, axis=0)
 664      array([[1.,  2.],
 665             [4.,  2.]])
 666      >>> np.nancumsum(a, axis=1)
 667      array([[1.,  3.],
 668             [3.,  3.]])
 669  
 670      r�rQrr)r2r�cumsum�rrQrrr1rrrr.s>rcCrtrOrr~rrr�_nancumprod_dispatcherpr�r�cCr�)aM
 671      Return the cumulative product of array elements over a given axis treating Not a
 672      Numbers (NaNs) as one.  The cumulative product does not change when NaNs are
 673      encountered and leading NaNs are replaced by ones.
 674  
 675      Ones are returned for slices that are all-NaN or empty.
 676  
 677      .. versionadded:: 1.12.0
 678  
 679      Parameters
 680      ----------
 681      a : array_like
 682          Input array.
 683      axis : int, optional
 684          Axis along which the cumulative product is computed.  By default
 685          the input is flattened.
 686      dtype : dtype, optional
 687          Type of the returned array, as well as of the accumulator in which
 688          the elements are multiplied.  If *dtype* is not specified, it
 689          defaults to the dtype of `a`, unless `a` has an integer dtype with
 690          a precision less than that of the default platform integer.  In
 691          that case, the default platform integer is used instead.
 692      out : ndarray, optional
 693          Alternative output array in which to place the result. It must
 694          have the same shape and buffer length as the expected output
 695          but the type of the resulting values will be cast if necessary.
 696  
 697      Returns
 698      -------
 699      nancumprod : ndarray
 700          A new array holding the result is returned unless `out` is
 701          specified, in which case it is returned.
 702  
 703      See Also
 704      --------
 705      numpy.cumprod : Cumulative product across array propagating NaNs.
 706      isnan : Show which elements are NaN.
 707  
 708      Examples
 709      --------
 710      >>> np.nancumprod(1)
 711      array([1])
 712      >>> np.nancumprod([1])
 713      array([1])
 714      >>> np.nancumprod([1, np.nan])
 715      array([1.,  1.])
 716      >>> a = np.array([[1, 2], [3, np.nan]])
 717      >>> np.nancumprod(a)
 718      array([1.,  2.,  6.,  6.])
 719      >>> np.nancumprod(a, axis=0)
 720      array([[1.,  2.],
 721             [3.,  2.]])
 722      >>> np.nancumprod(a, axis=1)
 723      array([[1.,  2.],
 724             [3.,  3.]])
 725  
 726      r|r�)r2r�cumprodr�rrrrts;rr$cCrtrOr)rrQrrrRr%rrr�_nanmean_dispatcher�rUr�cCs�t|d�\}}|durtj||||||d�S|durt�|�}|dur.t|jtj�s.td��|dur>t|jjtj�s>td��tj||tj	||d�}tj||||||d�}	t
 727  |	||d�}
 728  |dk}|��rltj
dtd	d
 729  �|
 730  S)a�
 731      Compute the arithmetic mean along the specified axis, ignoring NaNs.
 732  
 733      Returns the average of the array elements.  The average is taken over
 734      the flattened array by default, otherwise over the specified axis.
 735      `float64` intermediate and return values are used for integer inputs.
 736  
 737      For all-NaN slices, NaN is returned and a `RuntimeWarning` is raised.
 738  
 739      .. versionadded:: 1.8.0
 740  
 741      Parameters
 742      ----------
 743      a : array_like
 744          Array containing numbers whose mean is desired. If `a` is not an
 745          array, a conversion is attempted.
 746      axis : {int, tuple of int, None}, optional
 747          Axis or axes along which the means are computed. The default is to compute
 748          the mean of the flattened array.
 749      dtype : data-type, optional
 750          Type to use in computing the mean.  For integer inputs, the default
 751          is `float64`; for inexact inputs, it is the same as the input
 752          dtype.
 753      out : ndarray, optional
 754          Alternate output array in which to place the result.  The default
 755          is ``None``; if provided, it must have the same shape as the
 756          expected output, but the type will be cast if necessary. See
 757          :ref:`ufuncs-output-type` for more details.
 758      keepdims : bool, optional
 759          If this is set to True, the axes which are reduced are left
 760          in the result as dimensions with size one. With this option,
 761          the result will broadcast correctly against the original `a`.
 762  
 763          If the value is anything but the default, then
 764          `keepdims` will be passed through to the `mean` or `sum` methods
 765          of sub-classes of `ndarray`.  If the sub-classes methods
 766          does not implement `keepdims` any exceptions will be raised.
 767      where : array_like of bool, optional
 768          Elements to include in the mean. See `~numpy.ufunc.reduce` for details.
 769  
 770          .. versionadded:: 1.22.0
 771  
 772      Returns
 773      -------
 774      m : ndarray, see dtype parameter above
 775          If `out=None`, returns a new array containing the mean values,
 776          otherwise a reference to the output array is returned. Nan is
 777          returned for slices that contain only NaNs.
 778  
 779      See Also
 780      --------
 781      average : Weighted average
 782      mean : Arithmetic mean taken while not ignoring NaNs
 783      var, nanvar
 784  
 785      Notes
 786      -----
 787      The arithmetic mean is the sum of the non-NaN elements along the axis
 788      divided by the number of non-NaN elements.
 789  
 790      Note that for floating-point input, the mean is computed using the same
 791      precision the input has.  Depending on the input data, this can cause
 792      the results to be inaccurate, especially for `float32`.  Specifying a
 793      higher-precision accumulator using the `dtype` keyword can alleviate
 794      this issue.
 795  
 796      Examples
 797      --------
 798      >>> a = np.array([[1, np.nan], [3, 4]])
 799      >>> np.nanmean(a)
 800      2.6666666666666665
 801      >>> np.nanmean(a, axis=0)
 802      array([2.,  4.])
 803      >>> np.nanmean(a, axis=1)
 804      array([1.,  3.5]) # may vary
 805  
 806      rN�rQrrrRr%�+If a is inexact, then dtype must be inexact�)If a is inexact, then out must be inexact�rQrrRr%rzMean of empty slicerWr:)r2r�meanrr*r+r,�	TypeErrorry�intprMr\r?r@rA)rrQrrrRr%�arrr1�cnt�tot�avg�isbadrrrr�s,P�
 807  ��rcCs0t||d�\}}|jdkr|dStj||d�S)zu
 808      Private function for rank 1 arrays. Compute the median ignoring NaNs.
 809      See nanmedian for parameter usage
 810      �rCr�����)rFr>r�median)rBrCZarr1d_parsedrrr�_nanmedian1d"s
 811 812  r�cCs~|dus	|jdkr|��}|durt||�St||�|d<|S|j|dkr-t||||�St�t|||�}|dur=||d<|S)z�
 813      Private function that doesn't support extended axis or keepdims.
 814      These methods are extended to this function using _ureduce
 815      See nanmedian for parameter usage
 816  
 817      Nr|.iX)�ndim�ravelr��shape�_nanmedian_smallr�apply_along_axis)rrQrrC�part�resultrrr�
 818  _nanmedian3s
 819  r�cCs�tj�|t�|��}tjj|||d�}tt�|j����D]
 820  }t	j
 821  dtdd�q|jj
dkr3t�d�ntj}|durC|�|�|d<|S|�|�S)	z�
 822      sort + indexing median, faster for small medians along multiple
 823      dimensions due to the high overhead of apply_along_axis
 824  
 825      see nanmedian for parameter usage
 826      )rQrCr8�r:�m�NaTN.)r�ma�masked_arrayrr��range�
count_nonzeror1r�r?r@rArr�timedelta64ra�filled)rrQrrCr��i�
 827  fill_valuerrrr�Ms�
 828  r�cCrNrOr�rrQrrCrRrrr�_nanmedian_dispatcherarUr�cCs<t�|�}|jdkrtj||||d�Stj|t||||d�S)a
 829      Compute the median along the specified axis, while ignoring NaNs.
 830  
 831      Returns the median of the array elements.
 832  
 833      .. versionadded:: 1.9.0
 834  
 835      Parameters
 836      ----------
 837      a : array_like
 838          Input array or object that can be converted to an array.
 839      axis : {int, sequence of int, None}, optional
 840          Axis or axes along which the medians are computed. The default
 841          is to compute the median along a flattened version of the array.
 842          A sequence of axes is supported since version 1.9.0.
 843      out : ndarray, optional
 844          Alternative output array in which to place the result. It must
 845          have the same shape and buffer length as the expected output,
 846          but the type (of the output) will be cast if necessary.
 847      overwrite_input : bool, optional
 848         If True, then allow use of memory of input array `a` for
 849         calculations. The input array will be modified by the call to
 850         `median`. This will save memory when you do not need to preserve
 851         the contents of the input array. Treat the input as undefined,
 852         but it will probably be fully or partially sorted. Default is
 853         False. If `overwrite_input` is ``True`` and `a` is not already an
 854         `ndarray`, an error will be raised.
 855      keepdims : bool, optional
 856          If this is set to True, the axes which are reduced are left
 857          in the result as dimensions with size one. With this option,
 858          the result will broadcast correctly against the original `a`.
 859  
 860          If this is anything but the default value it will be passed
 861          through (in the special case of an empty array) to the
 862          `mean` function of the underlying array.  If the array is
 863          a sub-class and `mean` does not have the kwarg `keepdims` this
 864          will raise a RuntimeError.
 865  
 866      Returns
 867      -------
 868      median : ndarray
 869          A new array holding the result. If the input contains integers
 870          or floats smaller than ``float64``, then the output data-type is
 871          ``np.float64``.  Otherwise, the data-type of the output is the
 872          same as that of the input. If `out` is specified, that array is
 873          returned instead.
 874  
 875      See Also
 876      --------
 877      mean, median, percentile
 878  
 879      Notes
 880      -----
 881      Given a vector ``V`` of length ``N``, the median of ``V`` is the
 882      middle value of a sorted copy of ``V``, ``V_sorted`` - i.e.,
 883      ``V_sorted[(N-1)/2]``, when ``N`` is odd and the average of the two
 884      middle values of ``V_sorted`` when ``N`` is even.
 885  
 886      Examples
 887      --------
 888      >>> a = np.array([[10.0, 7, 4], [3, 2, 1]])
 889      >>> a[0, 1] = np.nan
 890      >>> a
 891      array([[10., nan,  4.],
 892             [ 3.,  2.,  1.]])
 893      >>> np.median(a)
 894      nan
 895      >>> np.nanmedian(a)
 896      3.0
 897      >>> np.nanmedian(a, axis=0)
 898      array([6.5, 2. , 2.5])
 899      >>> np.median(a, axis=1)
 900      array([nan,  2.])
 901      >>> b = a.copy()
 902      >>> np.nanmedian(b, axis=1, overwrite_input=True)
 903      array([7.,  2.])
 904      >>> assert not np.all(a==b)
 905      >>> b = a.copy()
 906      >>> np.nanmedian(b, axis=None, overwrite_input=True)
 907      3.0
 908      >>> assert not np.all(a==b)
 909  
 910      r�rrR)�funcrRrQrrC)rr&r>rr�_ureducer�r�rrrrfs
 911  U
 912  
 913  �r)�
interpolationcC�
 914  |||fSrOr�r�qrQrrC�methodrRr�rrr�_nanpercentile_dispatcher�s
 915  r��linearcCs\|durt�||d�}t�|�}t�|d�}t�|�}t�|�s$td��t|||||||�S)a�
 916      Compute the qth percentile of the data along the specified axis,
 917      while ignoring nan values.
 918  
 919      Returns the qth percentile(s) of the array elements.
 920  
 921      .. versionadded:: 1.9.0
 922  
 923      Parameters
 924      ----------
 925      a : array_like
 926          Input array or object that can be converted to an array, containing
 927          nan values to be ignored.
 928      q : array_like of float
 929          Percentile or sequence of percentiles to compute, which must be
 930          between 0 and 100 inclusive.
 931      axis : {int, tuple of int, None}, optional
 932          Axis or axes along which the percentiles are computed. The default
 933          is to compute the percentile(s) along a flattened version of the
 934          array.
 935      out : ndarray, optional
 936          Alternative output array in which to place the result. It must have
 937          the same shape and buffer length as the expected output, but the
 938          type (of the output) will be cast if necessary.
 939      overwrite_input : bool, optional
 940          If True, then allow the input array `a` to be modified by
 941          intermediate calculations, to save memory. In this case, the
 942          contents of the input `a` after this function completes is
 943          undefined.
 944      method : str, optional
 945          This parameter specifies the method to use for estimating the
 946          percentile.  There are many different methods, some unique to NumPy.
 947          See the notes for explanation.  The options sorted by their R type
 948          as summarized in the H&F paper [1]_ are:
 949  
 950          1. 'inverted_cdf'
 951          2. 'averaged_inverted_cdf'
 952          3. 'closest_observation'
 953          4. 'interpolated_inverted_cdf'
 954          5. 'hazen'
 955          6. 'weibull'
 956          7. 'linear'  (default)
 957          8. 'median_unbiased'
 958          9. 'normal_unbiased'
 959  
 960          The first three methods are discontinuous.  NumPy further defines the
 961          following discontinuous variations of the default 'linear' (7.) option:
 962  
 963          * 'lower'
 964          * 'higher',
 965          * 'midpoint'
 966          * 'nearest'
 967  
 968          .. versionchanged:: 1.22.0
 969              This argument was previously called "interpolation" and only
 970              offered the "linear" default and last four options.
 971  
 972      keepdims : bool, optional
 973          If this is set to True, the axes which are reduced are left in
 974          the result as dimensions with size one. With this option, the
 975          result will broadcast correctly against the original array `a`.
 976  
 977          If this is anything but the default value it will be passed
 978          through (in the special case of an empty array) to the
 979          `mean` function of the underlying array.  If the array is
 980          a sub-class and `mean` does not have the kwarg `keepdims` this
 981          will raise a RuntimeError.
 982  
 983      interpolation : str, optional
 984          Deprecated name for the method keyword argument.
 985  
 986          .. deprecated:: 1.22.0
 987  
 988      Returns
 989      -------
 990      percentile : scalar or ndarray
 991          If `q` is a single percentile and `axis=None`, then the result
 992          is a scalar. If multiple percentiles are given, first axis of
 993          the result corresponds to the percentiles. The other axes are
 994          the axes that remain after the reduction of `a`. If the input
 995          contains integers or floats smaller than ``float64``, the output
 996          data-type is ``float64``. Otherwise, the output data-type is the
 997          same as that of the input. If `out` is specified, that array is
 998          returned instead.
 999  
1000      See Also
1001      --------
1002      nanmean
1003      nanmedian : equivalent to ``nanpercentile(..., 50)``
1004      percentile, median, mean
1005      nanquantile : equivalent to nanpercentile, except q in range [0, 1].
1006  
1007      Notes
1008      -----
1009      For more information please see `numpy.percentile`
1010  
1011      Examples
1012      --------
1013      >>> a = np.array([[10., 7., 4.], [3., 2., 1.]])
1014      >>> a[0][1] = np.nan
1015      >>> a
1016      array([[10.,  nan,   4.],
1017            [ 3.,   2.,   1.]])
1018      >>> np.percentile(a, 50)
1019      nan
1020      >>> np.nanpercentile(a, 50)
1021      3.0
1022      >>> np.nanpercentile(a, 50, axis=0)
1023      array([6.5, 2. , 2.5])
1024      >>> np.nanpercentile(a, 50, axis=1, keepdims=True)
1025      array([[7.],
1026             [2.]])
1027      >>> m = np.nanpercentile(a, 50, axis=0)
1028      >>> out = np.zeros_like(m)
1029      >>> np.nanpercentile(a, 50, axis=0, out=out)
1030      array([6.5, 2. , 2.5])
1031      >>> m
1032      array([6.5,  2. ,  2.5])
1033  
1034      >>> b = a.copy()
1035      >>> np.nanpercentile(b, 50, axis=1, overwrite_input=True)
1036      array([7., 2.])
1037      >>> assert not np.all(a==b)
1038  
1039      References
1040      ----------
1041      .. [1] R. J. Hyndman and Y. Fan,
1042         "Sample quantiles in statistical packages,"
1043         The American Statistician, 50(4), pp. 361-365, 1996
1044  
1045      Nr
gY@z)Percentiles must be in the range [0, 100])r�_check_interpolation_as_methodrr&�true_divide�_quantile_is_validro�_nanquantile_uncheckedr�rrrr
�s�
1046  
1047  
1048  �r
cCr�rOrr�rrr�_nanquantile_dispatcheris
1049  r�cCsP|durt�||d�}t�|�}t�|�}t�|�std��t|||||||�S)a�
1050      Compute the qth quantile of the data along the specified axis,
1051      while ignoring nan values.
1052      Returns the qth quantile(s) of the array elements.
1053  
1054      .. versionadded:: 1.15.0
1055  
1056      Parameters
1057      ----------
1058      a : array_like
1059          Input array or object that can be converted to an array, containing
1060          nan values to be ignored
1061      q : array_like of float
1062          Quantile or sequence of quantiles to compute, which must be between
1063          0 and 1 inclusive.
1064      axis : {int, tuple of int, None}, optional
1065          Axis or axes along which the quantiles are computed. The
1066          default is to compute the quantile(s) along a flattened
1067          version of the array.
1068      out : ndarray, optional
1069          Alternative output array in which to place the result. It must
1070          have the same shape and buffer length as the expected output,
1071          but the type (of the output) will be cast if necessary.
1072      overwrite_input : bool, optional
1073          If True, then allow the input array `a` to be modified by intermediate
1074          calculations, to save memory. In this case, the contents of the input
1075          `a` after this function completes is undefined.
1076      method : str, optional
1077          This parameter specifies the method to use for estimating the
1078          quantile.  There are many different methods, some unique to NumPy.
1079          See the notes for explanation.  The options sorted by their R type
1080          as summarized in the H&F paper [1]_ are:
1081  
1082          1. 'inverted_cdf'
1083          2. 'averaged_inverted_cdf'
1084          3. 'closest_observation'
1085          4. 'interpolated_inverted_cdf'
1086          5. 'hazen'
1087          6. 'weibull'
1088          7. 'linear'  (default)
1089          8. 'median_unbiased'
1090          9. 'normal_unbiased'
1091  
1092          The first three methods are discontinuous.  NumPy further defines the
1093          following discontinuous variations of the default 'linear' (7.) option:
1094  
1095          * 'lower'
1096          * 'higher',
1097          * 'midpoint'
1098          * 'nearest'
1099  
1100          .. versionchanged:: 1.22.0
1101              This argument was previously called "interpolation" and only
1102              offered the "linear" default and last four options.
1103  
1104      keepdims : bool, optional
1105          If this is set to True, the axes which are reduced are left in
1106          the result as dimensions with size one. With this option, the
1107          result will broadcast correctly against the original array `a`.
1108  
1109          If this is anything but the default value it will be passed
1110          through (in the special case of an empty array) to the
1111          `mean` function of the underlying array.  If the array is
1112          a sub-class and `mean` does not have the kwarg `keepdims` this
1113          will raise a RuntimeError.
1114  
1115      interpolation : str, optional
1116          Deprecated name for the method keyword argument.
1117  
1118          .. deprecated:: 1.22.0
1119  
1120      Returns
1121      -------
1122      quantile : scalar or ndarray
1123          If `q` is a single percentile and `axis=None`, then the result
1124          is a scalar. If multiple quantiles are given, first axis of
1125          the result corresponds to the quantiles. The other axes are
1126          the axes that remain after the reduction of `a`. If the input
1127          contains integers or floats smaller than ``float64``, the output
1128          data-type is ``float64``. Otherwise, the output data-type is the
1129          same as that of the input. If `out` is specified, that array is
1130          returned instead.
1131  
1132      See Also
1133      --------
1134      quantile
1135      nanmean, nanmedian
1136      nanmedian : equivalent to ``nanquantile(..., 0.5)``
1137      nanpercentile : same as nanquantile, but with q in the range [0, 100].
1138  
1139      Notes
1140      -----
1141      For more information please see `numpy.quantile`
1142  
1143      Examples
1144      --------
1145      >>> a = np.array([[10., 7., 4.], [3., 2., 1.]])
1146      >>> a[0][1] = np.nan
1147      >>> a
1148      array([[10.,  nan,   4.],
1149            [ 3.,   2.,   1.]])
1150      >>> np.quantile(a, 0.5)
1151      nan
1152      >>> np.nanquantile(a, 0.5)
1153      3.0
1154      >>> np.nanquantile(a, 0.5, axis=0)
1155      array([6.5, 2. , 2.5])
1156      >>> np.nanquantile(a, 0.5, axis=1, keepdims=True)
1157      array([[7.],
1158             [2.]])
1159      >>> m = np.nanquantile(a, 0.5, axis=0)
1160      >>> out = np.zeros_like(m)
1161      >>> np.nanquantile(a, 0.5, axis=0, out=out)
1162      array([6.5, 2. , 2.5])
1163      >>> m
1164      array([6.5,  2. ,  2.5])
1165      >>> b = a.copy()
1166      >>> np.nanquantile(b, 0.5, axis=1, overwrite_input=True)
1167      array([7., 2.])
1168      >>> assert not np.all(a==b)
1169  
1170      References
1171      ----------
1172      .. [1] R. J. Hyndman and Y. Fan,
1173         "Sample quantiles in statistical packages,"
1174         The American Statistician, 50(4), pp. 361-365, 1996
1175  
1176      Nrz%Quantiles must be in the range [0, 1])rr�rr&r�ror�r�rrrrns
�
1177  
1178  
1179  �rc
1180  Cs6|jdkrtj||||d�Stj|t||||||d�S)z.Assumes that q is in [0, 1], and is an ndarrayrr�)r�r�rRrQrrCr�)r>rrrr��_nanquantile_ureduce_func)rr�rQrrCr�rRrrrr�s
1181  �r�cCsj|dus	|jdkr|��}t||||�}nt�t|||||�}|jdkr+t�||d�}|dur3||d<|S)z�
1182      Private function that doesn't support extended axis or keepdims.
1183      These methods are extended to this function using _ureduce
1184      See nanpercentile for parameter usage
1185      Nr|r.)r�r��_nanquantile_1drr��moveaxis)rr�rQrrCr�r�r�rrrr�s�
1186  r�cCsFt||d�\}}|jdkrtj|jtj|jd�dStj||||d�S)zw
1187      Private function for rank 1 arrays. Compute quantile ignoring NaNs.
1188      See nanpercentile for parameter usage
1189      r�rr!r)rCr�)	rFr>r�fullr�rarr�_quantile_unchecked)rBr�rCr�rrrr�6s
11901191  �r�cCrtrOr�rrQrr�ddofrRr%rrr�_nanvar_dispatcherErUr�c	Cs�t|d�\}}|durtj|||||||d�S|dur t�|�}|dur/t|jtj�s/td��|dur?t|jjtj�s?td��t|�tjurJtj	}	nd}	tj
1192  ||tj|	|d�}
1193  tj
1194  ||||	|d�}t||
1195  �}tj
|||d|d	�t|d|�}t|jjtj�r�tj||��||d
1196  �j}n	tj||||d
1197  �}tj
1198  ||||||d�}
z|
j}Wnty�t�|
�}Ynw||
1199  jkr�|
1200  �|�}
1201  |
1202  |}t|
|�}
|dk}t�|�r�tjdtd
d�t|
tj|�}
|
S)aM
1203      Compute the variance along the specified axis, while ignoring NaNs.
1204  
1205      Returns the variance of the array elements, a measure of the spread of
1206      a distribution.  The variance is computed for the flattened array by
1207      default, otherwise over the specified axis.
1208  
1209      For all-NaN slices or slices with zero degrees of freedom, NaN is
1210      returned and a `RuntimeWarning` is raised.
1211  
1212      .. versionadded:: 1.8.0
1213  
1214      Parameters
1215      ----------
1216      a : array_like
1217          Array containing numbers whose variance is desired.  If `a` is not an
1218          array, a conversion is attempted.
1219      axis : {int, tuple of int, None}, optional
1220          Axis or axes along which the variance is computed.  The default is to compute
1221          the variance of the flattened array.
1222      dtype : data-type, optional
1223          Type to use in computing the variance.  For arrays of integer type
1224          the default is `float64`; for arrays of float types it is the same as
1225          the array type.
1226      out : ndarray, optional
1227          Alternate output array in which to place the result.  It must have
1228          the same shape as the expected output, but the type is cast if
1229          necessary.
1230      ddof : int, optional
1231          "Delta Degrees of Freedom": the divisor used in the calculation is
1232          ``N - ddof``, where ``N`` represents the number of non-NaN
1233          elements. By default `ddof` is zero.
1234      keepdims : bool, optional
1235          If this is set to True, the axes which are reduced are left
1236          in the result as dimensions with size one. With this option,
1237          the result will broadcast correctly against the original `a`.
1238      where : array_like of bool, optional
1239          Elements to include in the variance. See `~numpy.ufunc.reduce` for
1240          details.
1241  
1242          .. versionadded:: 1.22.0
1243  
1244      Returns
1245      -------
1246      variance : ndarray, see dtype parameter above
1247          If `out` is None, return a new array containing the variance,
1248          otherwise return a reference to the output array. If ddof is >= the
1249          number of non-NaN elements in a slice or the slice contains only
1250          NaNs, then the result for that slice is NaN.
1251  
1252      See Also
1253      --------
1254      std : Standard deviation
1255      mean : Average
1256      var : Variance while not ignoring NaNs
1257      nanstd, nanmean
1258      :ref:`ufuncs-output-type`
1259  
1260      Notes
1261      -----
1262      The variance is the average of the squared deviations from the mean,
1263      i.e.,  ``var = mean(abs(x - x.mean())**2)``.
1264  
1265      The mean is normally calculated as ``x.sum() / N``, where ``N = len(x)``.
1266      If, however, `ddof` is specified, the divisor ``N - ddof`` is used
1267      instead.  In standard statistical practice, ``ddof=1`` provides an
1268      unbiased estimator of the variance of a hypothetical infinite
1269      population.  ``ddof=0`` provides a maximum likelihood estimate of the
1270      variance for normally distributed variables.
1271  
1272      Note that for complex numbers, the absolute value is taken before
1273      squaring, so that the result is always real and nonnegative.
1274  
1275      For floating-point input, the variance is computed using the same
1276      precision the input has.  Depending on the input data, this can cause
1277      the results to be inaccurate, especially for `float32` (see example
1278      below).  Specifying a higher-accuracy accumulator using the ``dtype``
1279      keyword can alleviate this issue.
1280  
1281      For this function to work on sub-classes of ndarray, they must define
1282      `sum` with the kwarg `keepdims`
1283  
1284      Examples
1285      --------
1286      >>> a = np.array([[1, np.nan], [3, 4]])
1287      >>> np.nanvar(a)
1288      1.5555555555555554
1289      >>> np.nanvar(a, axis=0)
1290      array([1.,  0.])
1291      >>> np.nanvar(a, axis=1)
1292      array([0.,  0.25])  # may vary
1293  
1294      rN�rQrrr�rRr%r�r�Tr�r3)rr4r%)rr%r�z"Degrees of freedom <= 0 for slice.rWr:)r2r�varrr*r+r,r��matrixrYryr�rM�subtractr7�complexfloating�multiply�conj�realr�rK�squeezer\r?r@rAra)rrQrrr�rRr%r�r1Z	_keepdimsr�r��sqrr�Zvar_ndimZdofr�rrrrJsV`�
1295  �
1296  �
1297  �
1298  
1299  
1300  
1301  �rcCrtrOrr�rrr�_nanstd_dispatcher�rUr�c		Csbt|||||||d�}t|tj�rtj||d�}|St|d�r*|j�t�|��}|St�|�}|S)a�
1302      Compute the standard deviation along the specified axis, while
1303      ignoring NaNs.
1304  
1305      Returns the standard deviation, a measure of the spread of a
1306      distribution, of the non-NaN array elements. The standard deviation is
1307      computed for the flattened array by default, otherwise over the
1308      specified axis.
1309  
1310      For all-NaN slices or slices with zero degrees of freedom, NaN is
1311      returned and a `RuntimeWarning` is raised.
1312  
1313      .. versionadded:: 1.8.0
1314  
1315      Parameters
1316      ----------
1317      a : array_like
1318          Calculate the standard deviation of the non-NaN values.
1319      axis : {int, tuple of int, None}, optional
1320          Axis or axes along which the standard deviation is computed. The default is
1321          to compute the standard deviation of the flattened array.
1322      dtype : dtype, optional
1323          Type to use in computing the standard deviation. For arrays of
1324          integer type the default is float64, for arrays of float types it
1325          is the same as the array type.
1326      out : ndarray, optional
1327          Alternative output array in which to place the result. It must have
1328          the same shape as the expected output but the type (of the
1329          calculated values) will be cast if necessary.
1330      ddof : int, optional
1331          Means Delta Degrees of Freedom.  The divisor used in calculations
1332          is ``N - ddof``, where ``N`` represents the number of non-NaN
1333          elements.  By default `ddof` is zero.
1334  
1335      keepdims : bool, optional
1336          If this is set to True, the axes which are reduced are left
1337          in the result as dimensions with size one. With this option,
1338          the result will broadcast correctly against the original `a`.
1339  
1340          If this value is anything but the default it is passed through
1341          as-is to the relevant functions of the sub-classes.  If these
1342          functions do not have a `keepdims` kwarg, a RuntimeError will
1343          be raised.
1344      where : array_like of bool, optional
1345          Elements to include in the standard deviation.
1346          See `~numpy.ufunc.reduce` for details.
1347  
1348          .. versionadded:: 1.22.0
1349  
1350      Returns
1351      -------
1352      standard_deviation : ndarray, see dtype parameter above.
1353          If `out` is None, return a new array containing the standard
1354          deviation, otherwise return a reference to the output array. If
1355          ddof is >= the number of non-NaN elements in a slice or the slice
1356          contains only NaNs, then the result for that slice is NaN.
1357  
1358      See Also
1359      --------
1360      var, mean, std
1361      nanvar, nanmean
1362      :ref:`ufuncs-output-type`
1363  
1364      Notes
1365      -----
1366      The standard deviation is the square root of the average of the squared
1367      deviations from the mean: ``std = sqrt(mean(abs(x - x.mean())**2))``.
1368  
1369      The average squared deviation is normally calculated as
1370      ``x.sum() / N``, where ``N = len(x)``.  If, however, `ddof` is
1371      specified, the divisor ``N - ddof`` is used instead. In standard
1372      statistical practice, ``ddof=1`` provides an unbiased estimator of the
1373      variance of the infinite population. ``ddof=0`` provides a maximum
1374      likelihood estimate of the variance for normally distributed variables.
1375      The standard deviation computed in this function is the square root of
1376      the estimated variance, so even with ``ddof=1``, it will not be an
1377      unbiased estimate of the standard deviation per se.
1378  
1379      Note that, for complex numbers, `std` takes the absolute value before
1380      squaring, so that the result is always real and nonnegative.
1381  
1382      For floating-point input, the *std* is computed using the same
1383      precision the input has. Depending on the input data, this can cause
1384      the results to be inaccurate, especially for float32 (see example
1385      below).  Specifying a higher-accuracy accumulator using the `dtype`
1386      keyword can alleviate this issue.
1387  
1388      Examples
1389      --------
1390      >>> a = np.array([[1, np.nan], [3, 4]])
1391      >>> np.nanstd(a)
1392      1.247219128924647
1393      >>> np.nanstd(a, axis=0)
1394      array([1., 0.])
1395      >>> np.nanstd(a, axis=1)
1396      array([0.,  0.5]) # may vary
1397  
1398      r�rr)rr5rr6�sqrt�hasattrrr+)	rrQrrr�rRr%r��stdrrrr�se�
1399  �
1400  �rrO)F)NNNNN)NN)NNNNNN)NNN)NNNN)NNF)NNFr�)Fr�)4�__doc__�	functoolsr?rr�	numpy.libr�
1401  numpy.corer�partial�array_function_dispatch�__all__r r2r7rFrMrTrYrrfrrkr
1402  rrr	rvrr{rrrr�rr�rr�r�r�r�rr�r
r�rr�r�r�r�rr�rrrrr�<module>s�
1403  -
1404  
1405  -,
1406  ��
1407  ��78
1408  �
1409  �g
1410  �
1411  �
1412  M
1413  A>��
1414  i
1415  
1416  
1417  �`���	����	�
1418  �
14191420  ������