
    Khj              	       l   S r SSKrSSKrSSKrSSKrSSKrSSKJr  / SQr	\R                  " \R                  SS9r\rS rS rS	 rS
 rS rS rS rS rS r\\\\\\\\S.rS rS rS rS rS rSS jr\" \5      SS j5       r SS jr\" \5      SS j5       r   SS jr!\" \!5      SS j5       r"g) z
Histogram-related functions
    N)	overrides)	histogramhistogramddhistogram_bin_edgesnumpy)modulec                 R    [        U R                  5       U R                  5       5      $ )zPeak-to-peak value of x.

This implementation avoids the problem of signed integer arrays having a
peak-to-peak value that cannot be represented with the array's data type.
This function returns an unsigned value for signed integer arrays.
)_unsigned_subtractmaxmin)xs    L/var/www/html/env/lib/python3.13/site-packages/numpy/lib/_histograms_impl.py_ptpr      s     aeegquuw//    c                 \    A[        U 5      [        R                  " U R                  5      -  $ )aN  
Square root histogram bin estimator.

Bin width is inversely proportional to the data size. Used by many
programs for its simplicity.

Parameters
----------
x : array_like
    Input data that is to be histogrammed, trimmed to range. May not
    be empty.

Returns
-------
h : An estimate of the optimal bin width for the given data.
)r   npsqrtsizer   ranges     r   _hist_bin_sqrtr       s"    " 	7RWWQVV_$$r   c                 b    A[        U 5      [        R                  " U R                  5      S-   -  $ )a  
Sturges histogram bin estimator.

A very simplistic estimator based on the assumption of normality of
the data. This estimator has poor performance for non-normal data,
which becomes especially obvious for large data sets. The estimate
depends only on size of the data.

Parameters
----------
x : array_like
    Input data that is to be histogrammed, trimmed to range. May not
    be empty.

Returns
-------
h : An estimate of the optimal bin width for the given data.
      ?)r   r   log2r   r   s     r   _hist_bin_sturgesr   5   s'    & 	7bggaffo+,,r   c                 @    A[        U 5      SU R                  S-  -  -  $ )a  
Rice histogram bin estimator.

Another simple estimator with no normality assumption. It has better
performance for large data than Sturges, but tends to overestimate
the number of bins. The number of bins is proportional to the cube
root of data size (asymptotically optimal). The estimate depends
only on size of the data.

Parameters
----------
x : array_like
    Input data that is to be histogrammed, trimmed to range. May not
    be empty.

Returns
-------
h : An estimate of the optimal bin width for the given data.
       @UUUUUU?)r   r   r   s     r   _hist_bin_ricer   L   s$    ( 	7cAFFw//00r   c                 ~    AS[         R                  S-  -  U R                  -  S-  [         R                  " U 5      -  $ )a~  
Scott histogram bin estimator.

The binwidth is proportional to the standard deviation of the data
and inversely proportional to the cube root of data size
(asymptotically optimal).

Parameters
----------
x : array_like
    Input data that is to be histogrammed, trimmed to range. May not
    be empty.

Returns
-------
h : An estimate of the optimal bin width for the given data.
g      8@      ?r   )r   pir   stdr   s     r   _hist_bin_scottr$   d   s5    $ 	255#:&)4rvvay@@r   c                 ,  ^ ^^^ T R                   m[        T 5      mTS::  d  TS:X  a  gUUUU 4S jn[        S[        [        R
                  " T5      5      5      n[        [        SUS-   5      US9nXC:X  a  [        R                  " S[        SS9  TU-  $ )	a  
Histogram bin estimator based on minimizing the estimated integrated squared error (ISE).

The number of bins is chosen by minimizing the estimated ISE against the unknown true distribution.
The ISE is estimated using cross-validation and can be regarded as a generalization of Scott's rule.
https://en.wikipedia.org/wiki/Histogram#Scott.27s_normal_reference_rule

This paper by Stone appears to be the origination of this rule.
https://digitalassets.lib.berkeley.edu/sdtr/ucb/text/34.pdf

Parameters
----------
x : array_like
    Input data that is to be histogrammed, trimmed to range. May not
    be empty.
range : (float, float)
    The lower and upper range of the bins.

Returns
-------
h : An estimate of the optimal bin width for the given data.
   r   c                    > TU -  n[         R                  " TU TS9S   T-  nSTS-   UR                  U5      -  -
  U-  $ )N)binsr   r      r&   )r   r   dot)nbinshhp_knptp_xr   r   s      r   jhat_hist_bin_stone.<locals>.jhat   sI    U]ll156q9A=QUcggcl**b00r   d   )keyz/The number of bins estimated may be suboptimal.   
stacklevel)r   r   r   intr   r   r   _rangewarningswarnRuntimeWarning)r   r   r0   nbins_upper_boundr+   r.   r/   s   ``   @@r   _hist_bin_stoner=   z   s    0 	
AGEAv!1 1
 CRWWQZ1q+a/0d;E!G$	45=r   c                 h   AU R                   S:  Ga   [        R                  " SU R                   S-
  -  U R                   S-   U R                   S-   -  -  5      n[        R                  " U 5      nUS:  a  U [        R                  " U 5      -
  n[        R
                  " XCU5        [        R                  " USU5        [        R                  " U5      n[        U 5      S[        R                  " U R                   5      -   [        R                  " S[        R                  " U5      U-  -   5      -   -  $ g)a  
Doane's histogram bin estimator.

Improved version of Sturges' formula which works better for
non-normal data. See
stats.stackexchange.com/questions/55134/doanes-formula-for-histogram-binning

Parameters
----------
x : array_like
    Input data that is to be histogrammed, trimmed to range. May not
    be empty.

Returns
-------
h : An estimate of the optimal bin width for the given data.
r)   g      @r   r4   g        )
r   r   r   r#   meantrue_dividepowerr   r   absolute)r   r   sg1sigmatempg1s         r   _hist_bin_doanerG      s    $ 	vvzggcQVVaZ(QVVc\affqj,IJKq	3; rwwqz>DNN4-HHT1d#B7cBGGAFFO3$&GGC"++b/C2G,G$HI J Jr   c                     A[         R                  " [         R                  " U SS/5      6 nSU-  U R                  S-  -  $ )a  
The Freedman-Diaconis histogram bin estimator.

The Freedman-Diaconis rule uses interquartile range (IQR) to
estimate binwidth. It is considered a variation of the Scott rule
with more robustness as the IQR is less affected by outliers than
the standard deviation. However, the IQR depends on fewer points
than the standard deviation, so it is less accurate, especially for
long tailed distributions.

If the IQR is 0, this function returns 0 for the bin width.
Binwidth is inversely proportional to the cube root of data size
(asymptotically optimal).

Parameters
----------
x : array_like
    Input data that is to be histogrammed, trimmed to range. May not
    be empty.

Returns
-------
h : An estimate of the optimal bin width for the given data.
K      r   gUUUUUUտ)r   subtract
percentiler   )r   r   iqrs      r   _hist_bin_fdrN      s<    2 	
++r}}QR1
2C9qvv*---r   c                 X    [        X5      n[        X5      nAU(       a  [        X#5      $ U$ )av  
Histogram bin estimator that uses the minimum width of the
Freedman-Diaconis and Sturges estimators if the FD bin width is non-zero.
If the bin width from the FD estimator is 0, the Sturges estimator is used.

The FD estimator is usually the most robust method, but its width
estimate tends to be too large for small `x` and bad for data with limited
variance. The Sturges estimator is quite good for small (<1000) datasets
and is the default in the R language. This method gives good off-the-shelf
behaviour.

If there is limited variance the IQR can be 0, which results in the
FD bin width being 0 too. This is not a valid bin width, so
``np.histogram_bin_edges`` chooses 1 bin instead, which may not be optimal.
If the IQR is 0, it's unlikely any variance-based estimators will be of
use, so we revert to the Sturges estimator, which only uses the size of the
dataset in its calculation.

Parameters
----------
x : array_like
    Input data that is to be histogrammed, trimmed to range. May not
    be empty.

Returns
-------
h : An estimate of the optimal bin width for the given data.

See Also
--------
_hist_bin_fd, _hist_bin_sturges
)rN   r   r   )r   r   fd_bw
sturges_bws       r   _hist_bin_autorR      s2    B "E"1,J5%% r   )stoneautodoanefdricescottr   sturgesc                    [         R                  " U 5      n U R                  [         R                  :X  aa  [        R
                  " SR                  U R                  [         R                  5      [        SS9  U R                  [         R                  5      n UbK  [         R                  " U5      nUR                  U R                  :w  a  [        S5      eUR                  5       nU R                  5       n X4$ )z9Check a and weights have matching shapes, and ravel both z1Converting input from {} to {} for compatibility.r4   r5   z(weights should have the same shape as a.)r   asarraydtypeboolr9   r:   formatuint8r;   astypeshape
ValueErrorravel)aweightss     r   _ravel_and_check_weightsrf     s    


1A 	ww"''Ivaggrxx0$	4 HHRXX**W%==AGG#:< <--/		A:r   c                    Ube  Uu  p#X#:  a  [        S5      e[        R                  " U5      (       a  [        R                  " U5      (       d  [        SR                  X#5      5      eOU R                  S:X  a  Su  p#OoU R                  5       U R                  5       p2[        R                  " U5      (       a  [        R                  " U5      (       d  [        SR                  X#5      5      eX#:X  a
  US-
  nUS-   nX#4$ )zR
Determine the outer bin edges to use, from either the data or the range
argument
z/max must be larger than min in range parameter.z(supplied range of [{}, {}] is not finiter   )r   r&   z,autodetected range of [{}, {}] is not finiter!   )rb   r   isfiniter^   r   r   r   )rd   r   
first_edge	last_edges       r   _get_outer_edgesrk   /  s    
  %
!AC CJ''BKK	,B,B:AA*XZ Z -C 
1 $
I !IJ''BKK	,B,B>EEj\^ ^ #%
O	  r   c           
      <   [         R                  [         R                  [         R                  [         R                  [         R
                  [         R                  [         R                  [         R                  [         R                  [         R                  0n[         R                  " X5      n X#R                     n[         R                  " [         R                  " XS9[         R                  " XS9SUS9$ ! [         a    [         R                  " XUS9s $ f = f)z
Subtract two values where a >= b, and produce an unsigned result

This is needed when finding the difference between the upper and lower
bound of an int16 histogram
r\   unsafe)castingr\   )r   byteubyteshortushortintcuintcint_uintlonglong	ulonglongresult_typetyperK   r[   KeyError)rd   bsigned_to_unsigneddtunsigned_dts        r   r
   r
   M  s     	
"))


R\\ 
	B	@(1 {{2::a2BJJq4K#+;@ 	@  +{{1r**+s   0C9 9DDc                 p   SnSn[        U[        5      (       Ga  UnU[        ;  a  [        SR	                  U5      5      eUb  [        S5      e[        X5      u  pxUb3  X:  n	XU:*  -  n	[        R                  R                  U	5      (       d  X	   n U R                  S:X  a  SnGO>[        U   " XU45      n
U
(       ah  [        R                  " U R                  [        R                  5      (       a  U
S:  a  Sn
[        [        R                  " [!        X5      U
-  5      5      nOSnO[        R"                  " U5      S:X  a6   [$        R&                  " U5      nUS:  a  [        S5      e[        X5      u  pxOk[        R"                  " U5      S:X  aF  [        R(                  " U5      n[        R*                  " USS USS :  5      (       a  [        S	5      eO[        S
5      eUb  [        R,                  " WWU 5      n[        R                  " U[        R                  5      (       a  [        R,                  " U[.        5      n[        R0                  " XxUS-   SUS9n[        R*                  " USS USS :  5      (       a  [        SU S35      eXWX44$ US4$ ! [
         a  n[        S5      UeSnAff = f)a  
Computes the bins used internally by `histogram`.

Parameters
==========
a : ndarray
    Ravelled data array
bins, range
    Forwarded arguments from `histogram`.
weights : ndarray, optional
    Ravelled weights array, or None

Returns
=======
bin_edges : ndarray
    Array of bin edges
uniform_bins : (Number, Number, int):
    The upper bound, lowerbound, and number of bins, used in the optimized
    implementation of `histogram` that works on uniform bins.
Nz({!r} is not a valid estimator for `bins`zMAutomated estimation of the number of bins is not supported for weighted datar   r&   z0`bins` must be an integer, a string, or an arrayz(`bins` must be positive, when an integerz1`bins` must increase monotonically, when an arrayz `bins` must be 1d, when an arrayT)endpointr\   z,Too many bins for data range. Cannot create z finite-sized bins.)
isinstancestr_hist_bin_selectorsrb   r^   	TypeErrorrk   r   logical_andreducer   
issubdtyper\   integerr7   ceilr
   ndimoperatorindexr[   anyrz   floatlinspace)rd   r(   r   re   n_equal_bins	bin_edgesbin_nameri   rj   keepwidthebin_types                r   _get_bin_edgesr   i  s   , LI$ ..:AA(KM M F G G !1 :
 OD)^$D>>((..G66Q;L (1!)5LME=="**55%!)E"277+=i+TW\+\#]^  !	!		K#>>$/L !GHH 0 :
I	!	JJt$	66)CR.9QR=011CE E 2
 ;<< >>*i;==2::..~~h6H KK<!#3+	 66)CR.IabM122>|n M% &' ' y???$G  	KBDIJK	Ks   J 
J5$J00J5c                 ~    [         R                  " U R                  USS S5      U R                  USS S5      45      $ )z
Like `searchsorted`, but where the last item in `v` is placed on the right.

In the context of a histogram, this makes the last bin edge inclusive
Nr   leftright)r   concatenatesearchsorted)rd   vs     r   _search_sorted_inclusiver     sB     >>	q"vv&	qvw'  r   c                 
    XU4$ N )rd   r(   r   re   s       r   _histogram_bin_edges_dispatcherr     s    Wr   c                 <    [        X5      u  p[        XX#5      u  pEU$ )a  
Function to calculate only the edges of the bins used by the `histogram`
function.

Parameters
----------
a : array_like
    Input data. The histogram is computed over the flattened array.
bins : int or sequence of scalars or str, optional
    If `bins` is an int, it defines the number of equal-width
    bins in the given range (10, by default). If `bins` is a
    sequence, it defines the bin edges, including the rightmost
    edge, allowing for non-uniform bin widths.

    If `bins` is a string from the list below, `histogram_bin_edges` will
    use the method chosen to calculate the optimal bin width and
    consequently the number of bins (see the Notes section for more detail
    on the estimators) from the data that falls within the requested range.
    While the bin width will be optimal for the actual data
    in the range, the number of bins will be computed to fill the
    entire range, including the empty portions. For visualisation,
    using the 'auto' option is suggested. Weighted data is not
    supported for automated bin size selection.

    'auto'
        Minimum bin width between the 'sturges' and 'fd' estimators.
        Provides good all-around performance.

    'fd' (Freedman Diaconis Estimator)
        Robust (resilient to outliers) estimator that takes into
        account data variability and data size.

    'doane'
        An improved version of Sturges' estimator that works better
        with non-normal datasets.

    'scott'
        Less robust estimator that takes into account data variability
        and data size.

    'stone'
        Estimator based on leave-one-out cross-validation estimate of
        the integrated squared error. Can be regarded as a generalization
        of Scott's rule.

    'rice'
        Estimator does not take variability into account, only data
        size. Commonly overestimates number of bins required.

    'sturges'
        R's default method, only accounts for data size. Only
        optimal for gaussian data and underestimates number of bins
        for large non-gaussian datasets.

    'sqrt'
        Square root (of data size) estimator, used by Excel and
        other programs for its speed and simplicity.

range : (float, float), optional
    The lower and upper range of the bins.  If not provided, range
    is simply ``(a.min(), a.max())``.  Values outside the range are
    ignored. The first element of the range must be less than or
    equal to the second. `range` affects the automatic bin
    computation as well. While bin width is computed to be optimal
    based on the actual data within `range`, the bin count will fill
    the entire range including portions containing no data.

weights : array_like, optional
    An array of weights, of the same shape as `a`.  Each value in
    `a` only contributes its associated weight towards the bin count
    (instead of 1). This is currently not used by any of the bin estimators,
    but may be in the future.

Returns
-------
bin_edges : array of dtype float
    The edges to pass into `histogram`

See Also
--------
histogram

Notes
-----
The methods to estimate the optimal number of bins are well founded
in literature, and are inspired by the choices R provides for
histogram visualisation. Note that having the number of bins
proportional to :math:`n^{1/3}` is asymptotically optimal, which is
why it appears in most estimators. These are simply plug-in methods
that give good starting points for number of bins. In the equations
below, :math:`h` is the binwidth and :math:`n_h` is the number of
bins. All estimators that compute bin counts are recast to bin width
using the `ptp` of the data. The final bin count is obtained from
``np.round(np.ceil(range / h))``. The final bin width is often less
than what is returned by the estimators below.

'auto' (minimum bin width of the 'sturges' and 'fd' estimators)
    A compromise to get a good value. For small datasets the Sturges
    value will usually be chosen, while larger datasets will usually
    default to FD.  Avoids the overly conservative behaviour of FD
    and Sturges for small and large datasets respectively.
    Switchover point is usually :math:`a.size \approx 1000`.

'fd' (Freedman Diaconis Estimator)
    .. math:: h = 2 \frac{IQR}{n^{1/3}}

    The binwidth is proportional to the interquartile range (IQR)
    and inversely proportional to cube root of a.size. Can be too
    conservative for small datasets, but is quite good for large
    datasets. The IQR is very robust to outliers.

'scott'
    .. math:: h = \sigma \sqrt[3]{\frac{24 \sqrt{\pi}}{n}}

    The binwidth is proportional to the standard deviation of the
    data and inversely proportional to cube root of ``x.size``. Can
    be too conservative for small datasets, but is quite good for
    large datasets. The standard deviation is not very robust to
    outliers. Values are very similar to the Freedman-Diaconis
    estimator in the absence of outliers.

'rice'
    .. math:: n_h = 2n^{1/3}

    The number of bins is only proportional to cube root of
    ``a.size``. It tends to overestimate the number of bins and it
    does not take into account data variability.

'sturges'
    .. math:: n_h = \log _{2}(n) + 1

    The number of bins is the base 2 log of ``a.size``.  This
    estimator assumes normality of data and is too conservative for
    larger, non-normal datasets. This is the default method in R's
    ``hist`` method.

'doane'
    .. math:: n_h = 1 + \log_{2}(n) +
                    \log_{2}\left(1 + \frac{|g_1|}{\sigma_{g_1}}\right)

        g_1 = mean\left[\left(\frac{x - \mu}{\sigma}\right)^3\right]

        \sigma_{g_1} = \sqrt{\frac{6(n - 2)}{(n + 1)(n + 3)}}

    An improved version of Sturges' formula that produces better
    estimates for non-normal datasets. This estimator attempts to
    account for the skew of the data.

'sqrt'
    .. math:: n_h = \sqrt n

    The simplest and fastest estimator. Only takes into account the
    data size.

Additionally, if the data is of integer dtype, then the binwidth will never
be less than 1.

Examples
--------
>>> import numpy as np
>>> arr = np.array([0, 0, 0, 1, 2, 3, 3, 4, 5])
>>> np.histogram_bin_edges(arr, bins='auto', range=(0, 1))
array([0.  , 0.25, 0.5 , 0.75, 1.  ])
>>> np.histogram_bin_edges(arr, bins=2)
array([0. , 2.5, 5. ])

For consistency with histogram, an array of pre-computed bins is
passed through unmodified:

>>> np.histogram_bin_edges(arr, [1, 2])
array([1, 2])

This function allows one set of bins to be computed, and reused across
multiple histograms:

>>> shared_bins = np.histogram_bin_edges(arr, bins='auto')
>>> shared_bins
array([0., 1., 2., 3., 4., 5.])

>>> group_id = np.array([0, 1, 1, 0, 1, 1, 0, 1, 1])
>>> hist_0, _ = np.histogram(arr[group_id == 0], bins=shared_bins)
>>> hist_1, _ = np.histogram(arr[group_id == 1], bins=shared_bins)

>>> hist_0; hist_1
array([1, 1, 0, 1, 0])
array([2, 0, 1, 1, 2])

Which gives more easily comparable results than using separate bins for
each histogram:

>>> hist_0, bins_0 = np.histogram(arr[group_id == 0], bins='auto')
>>> hist_1, bins_1 = np.histogram(arr[group_id == 1], bins='auto')
>>> hist_0; hist_1
array([1, 1, 1])
array([2, 1, 1, 2])
>>> bins_0; bins_1
array([0., 1., 2., 3.])
array([0.  , 1.25, 2.5 , 3.75, 5.  ])

)rf   r   )rd   r(   r   re   r   _s         r   r   r     s%    T *!5JA!!5:LIr   c                 
    XU4$ r   r   )rd   r(   r   densityre   s        r   _histogram_dispatcherr     s    Wr   c           	         [        X5      u  p[        XX$5      u  pVUc%  [        R                  " [        R                  5      nOUR                  nSnUSL =(       d[    [        R
                  " UR                  [        R                  5      =(       d%    [        R
                  " UR                  [        5      n	UGb  U	(       Ga  Uu  pn[        R                  " X5      nUn[        X5      n[        S[        U 5      U5       GH  nU UUU-    nUc  SnOUUUU-    nUU
:  nUUU:*  -  n[        R                  R                  U5      (       d  UU   nUb  UU   nUR                  UR                  SS9n[        UU
5      U-  U-  nUR                  [        R                  5      nUUU:H  ==   S-  ss'   UUU   :  nUU==   S-  ss'   UUUS-      :  UUS-
  :g  -  nUU==   S-  ss'   UR                  S:X  ai  U=R                   [        R"                  " UUR                   US9-  sl        U=R$                  [        R"                  " UUR$                  US9-  sl        GMb  U[        R"                  " UUUS9R                  U5      -  nGM     GO[        R                  " UR&                  U5      nUcI  [        S[        U 5      U5       H.  n[        R(                  " U UUU-    5      nU[+        UU5      -  nM0     O[        R                  " SUS	9n[        S[        U 5      U5       Hm  nU UUU-    nUUUU-    n[        R,                  " U5      nUU   nUU   n[        R.                  " UUR1                  5       45      n[+        UU5      nUUU   -  nMo     [        R2                  " U5      nU(       aG  [        R4                  " [        R2                  " U5      [6        5      nUU-  UR9                  5       -  U4$ X4$ )
aV  
Compute the histogram of a dataset.

Parameters
----------
a : array_like
    Input data. The histogram is computed over the flattened array.
bins : int or sequence of scalars or str, optional
    If `bins` is an int, it defines the number of equal-width
    bins in the given range (10, by default). If `bins` is a
    sequence, it defines a monotonically increasing array of bin edges,
    including the rightmost edge, allowing for non-uniform bin widths.

    If `bins` is a string, it defines the method used to calculate the
    optimal bin width, as defined by `histogram_bin_edges`.

range : (float, float), optional
    The lower and upper range of the bins.  If not provided, range
    is simply ``(a.min(), a.max())``.  Values outside the range are
    ignored. The first element of the range must be less than or
    equal to the second. `range` affects the automatic bin
    computation as well. While bin width is computed to be optimal
    based on the actual data within `range`, the bin count will fill
    the entire range including portions containing no data.
weights : array_like, optional
    An array of weights, of the same shape as `a`.  Each value in
    `a` only contributes its associated weight towards the bin count
    (instead of 1). If `density` is True, the weights are
    normalized, so that the integral of the density over the range
    remains 1.
    Please note that the ``dtype`` of `weights` will also become the
    ``dtype`` of the returned accumulator (`hist`), so it must be
    large enough to hold accumulated values as well.
density : bool, optional
    If ``False``, the result will contain the number of samples in
    each bin. If ``True``, the result is the value of the
    probability *density* function at the bin, normalized such that
    the *integral* over the range is 1. Note that the sum of the
    histogram values will not be equal to 1 unless bins of unity
    width are chosen; it is not a probability *mass* function.

Returns
-------
hist : array
    The values of the histogram. See `density` and `weights` for a
    description of the possible semantics.  If `weights` are given,
    ``hist.dtype`` will be taken from `weights`.
bin_edges : array of dtype float
    Return the bin edges ``(length(hist)+1)``.


See Also
--------
histogramdd, bincount, searchsorted, digitize, histogram_bin_edges

Notes
-----
All but the last (righthand-most) bin is half-open.  In other words,
if `bins` is::

  [1, 2, 3, 4]

then the first bin is ``[1, 2)`` (including 1, but excluding 2) and
the second ``[2, 3)``.  The last bin, however, is ``[3, 4]``, which
*includes* 4.


Examples
--------
>>> import numpy as np
>>> np.histogram([1, 2, 1], bins=[0, 1, 2, 3])
(array([0, 2, 1]), array([0, 1, 2, 3]))
>>> np.histogram(np.arange(4), bins=np.arange(5), density=True)
(array([0.25, 0.25, 0.25, 0.25]), array([0, 1, 2, 3, 4]))
>>> np.histogram([[1, 2, 1], [1, 0, 1]], bins=[0,1,2,3])
(array([1, 4, 1]), array([0, 1, 2, 3]))

>>> a = np.arange(5)
>>> hist, bin_edges = np.histogram(a, density=True)
>>> hist
array([0.5, 0. , 0.5, 0. , 0. , 0.5, 0. , 0.5, 0. , 0.5])
>>> hist.sum()
2.4999999999999996
>>> np.sum(hist * np.diff(bin_edges))
1.0

Automated Bin Selection Methods example, using 2 peak random data
with 2000 points.

.. plot::
    :include-source:

    import matplotlib.pyplot as plt
    import numpy as np

    rng = np.random.RandomState(10)  # deterministic random data
    a = np.hstack((rng.normal(size=1000),
                   rng.normal(loc=5, scale=2, size=1000)))
    plt.hist(a, bins='auto')  # arguments are passed to np.histogram
    plt.title("Histogram with 'auto' bins")
    plt.show()

Ni   r   F)copyr&   c)re   	minlengthrm   )rf   r   r   r\   intpcan_castdoublecomplexzerosr
   r8   lenr   r   r`   kindrealbincountimagra   sortr   argsortr   cumsumdiffarrayr   sum) rd   r(   r   r   re   r   uniform_binsntypeBLOCKsimple_weightsri   rj   r   r.   norm_numerator
norm_denomitmp_atmp_wr   	f_indicesindices	decrement	incrementcum_nsazerosorting_indexswcw	bin_indexdbs                                    r   r   r     s   R *!5JA,QeEI ! E
 	4 	,
GMM299-	,
GMM7+  N /;+
| HH\) &'	>
 3q65)Aa%LE!e), Z'DUi'(D>>((..d$!$KE
 LLuL=E -UJ?*L)*I&&rww/GG|+,1, 	' 22II!#9Wq[#99#|a'779II!# zzS "++guzz0<> >"++guzz0<> > R[[%+799?GW *^ %0?As1vu-WWQq5\*1"i@@ . 88AU+DAs1vu-!AeG!E'* "

5 1=)=)^^T299;$784RC	I& . GGENXXbggi(%0tAEEG|Y&&<r   c              #      #    [        U S5      (       a  U v   O
U  S h  vN   [        R                  " [        5         U S h  vN   S S S 5        Uv   g  N6 N! , (       d  f       N= f7f)Nra   )hasattr
contextlibsuppressr   )sampler(   r   r   re   s        r   _histogramdd_dispatcherr     sO     vw			Y	' 
(
M 	 
(	's8   A*AA*AAAA*A
A'#A*c                   ^ ^  T R                   u  pV[        R                  " U[        R                  5      nUS/-  mUS/-  nUb  [        R                  " U5      n [        U5      n	X:w  a  [        S5      e Uc  SU-  nO[        U5      U:w  a  [        S5      e[        U5       GHT  n
[        R                  " X   5      S:X  ap  X   S:  a  [        SR                  U
5      5      e[        T SS2U
4   X*   5      u  p [        R                   " X   5      n[        R"                  " XUS-   5      TU
'   O[        R                  " X   5      S:X  a`  [        R                  " X   5      TU
'   [        R$                  " TU
   SS	 TU
   SS :  5      (       a  [        S
R                  U
5      5      eO[        SR                  U
5      5      e[        TU
   5      S-   Xz'   [        R&                  " TU
   5      X'   GMW     [)        UU 4S j[        U5       5       5      n[        U5       H$  n
T SS2U
4   TU
   S	   :H  nX   U==   S-  ss'   M&     [        R*                  " X5      n[        R,                  " UXGR/                  5       S9nUR1                  U5      nUR3                  [4        SS9nU[7        SS	5      4-  nUU   nU(       ab  UR9                  5       n[        U5       H>  n
[        R:                  " U[<        5      nXz   S-
  UU
'   UX   R1                  U5      -  nM@     UU-  nUR                   US-
  :g  R%                  5       (       a  [?        S5      eUT4$ ! [        [        4 a2    [        R                  " T 5      R
                  m T R                   u  pV GNf = f! [         a	    Xa/-  n GN@f = f! [         a   n[        SR                  U
5      5      UeSnAff = f)a  
Compute the multidimensional histogram of some data.

Parameters
----------
sample : (N, D) array, or (N, D) array_like
    The data to be histogrammed.

    Note the unusual interpretation of sample when an array_like:

    * When an array, each row is a coordinate in a D-dimensional space -
      such as ``histogramdd(np.array([p1, p2, p3]))``.
    * When an array_like, each element is the list of values for single
      coordinate - such as ``histogramdd((X, Y, Z))``.

    The first form should be preferred.

bins : sequence or int, optional
    The bin specification:

    * A sequence of arrays describing the monotonically increasing bin
      edges along each dimension.
    * The number of bins for each dimension (nx, ny, ... =bins)
    * The number of bins for all dimensions (nx=ny=...=bins).

range : sequence, optional
    A sequence of length D, each an optional (lower, upper) tuple giving
    the outer bin edges to be used if the edges are not given explicitly in
    `bins`.
    An entry of None in the sequence results in the minimum and maximum
    values being used for the corresponding dimension.
    The default, None, is equivalent to passing a tuple of D None values.
density : bool, optional
    If False, the default, returns the number of samples in each bin.
    If True, returns the probability *density* function at the bin,
    ``bin_count / sample_count / bin_volume``.
weights : (N,) array_like, optional
    An array of values `w_i` weighing each sample `(x_i, y_i, z_i, ...)`.
    Weights are normalized to 1 if density is True. If density is False,
    the values of the returned histogram are equal to the sum of the
    weights belonging to the samples falling into each bin.

Returns
-------
H : ndarray
    The multidimensional histogram of sample x. See density and weights
    for the different possible semantics.
edges : tuple of ndarrays
    A tuple of D arrays describing the bin edges for each dimension.

See Also
--------
histogram: 1-D histogram
histogram2d: 2-D histogram

Examples
--------
>>> import numpy as np
>>> rng = np.random.default_rng()
>>> r = rng.normal(size=(100,3))
>>> H, edges = np.histogramdd(r, bins = (5, 8, 4))
>>> H.shape, edges[0].size, edges[1].size, edges[2].size
((5, 8, 4), 6, 9, 5)

NzEThe dimension of bins must be equal to the dimension of the sample x.r   z0range argument must have one entry per dimensionr   r&   z,`bins[{}]` must be positive, when an integerz,`bins[{}]` must be an integer, when a scalarr   z:`bins[{}]` must be monotonically increasing, when an arrayz'`bins[{}]` must be a scalar or 1d arrayc              3   d   >#    U  H%  n[         R                  " TU   TS S 2U4   SS9v   M'     g 7f)Nr   )side)r   r   ).0r   edgesr   s     r   	<genexpr>histogramdd.<locals>.<genexpr>  s3       A 	a&A,W=s   -0)r   safe)ro   r)   zInternal Shape Error) ra   AttributeErrorrb   r   
atleast_2dTemptyr   r[   r   r   r8   r   r^   rk   r   r   r   r   r   tupleravel_multi_indexr   prodreshaper`   r   slicer   onesr7   RuntimeError)r   r(   r   r   re   NDnbindedgesMr   sminsmaxr.   r   Ncounton_edgexyhistcoresra   r   s   `                     @r   r   r     s   H|| 88ArwwDtfHEvXF**W%I6   }!	UqKLL AY7747q w{ BII!LN N)&1+ux@JDNN47+ {{4q1u5E!HWWTW"zz$'*E!HvveAhsmeAhqrl233 PVAY    4
 9@@CE E eAh-!#GGE!H%	5 :    F AY!Q$<58B</	'a	  
		f	+B ;;r7iik:D <<D ;;uf;-D eArl_D:DHHJAGGAsOEw{E!H&)++E22D  		

dQh##%%"$ 	$;M J' v&((||1"  x(  ?FFqIs;   M" N' N=">N$#N$'N:9N:=
O'O""O')NNN)
   NN)NNNN)r   NNN)#__doc__r   	functoolsr   r9   r   r   numpy._corer   __all__partialarray_function_dispatchr   r8   r   r   r   r   r$   r=   rG   rN   rR   r   rf   rk   r
   r   r   r   r   r   r   r   r   r   r   r   <module>r     s)        !
=#++%%g7 
 
0%*-.10A,'T F.<(V !0- /)- /-"35 *!<@8aH	 89K :K^ 9=
 ./U 0Up DH$( 01l 2lr   