
    (ph                         S SK r S SKJrJr  S SKrS SKJr  S SKJ	r	  / SQr
\	" SS5      r  SS jr\	" S	S
5      r  SS jr\	" SS5      rS r   SS jrS rS rSS jrS rg)    N)catch_warningssimplefilter)index)
namedtuple)binned_statisticbinned_statistic_2dbinned_statistic_ddBinnedStatisticResult)	statistic	bin_edges	binnumberc                      [        U5      nUS:w  a  [        R                  " U[        5      /nUb  [        U5      S:X  a  U/n[        U /XX45      u  pgn[        XgS   U5      $ ! [         a    Sn Nef = f)a  
Compute a binned statistic for one or more sets of data.

This is a generalization of a histogram function.  A histogram divides
the space into bins, and returns the count of the number of points in
each bin.  This function allows the computation of the sum, mean, median,
or other statistic of the values (or set of values) within each bin.

Parameters
----------
x : (N,) array_like
    A sequence of values to be binned.
values : (N,) array_like or list of (N,) array_like
    The data on which the statistic will be computed.  This must be
    the same shape as `x`, or a set of sequences - each the same shape as
    `x`.  If `values` is a set of sequences, the statistic will be computed
    on each independently.
statistic : string or callable, optional
    The statistic to compute (default is 'mean').
    The following statistics are available:

      * 'mean' : compute the mean of values for points within each bin.
        Empty bins will be represented by NaN.
      * 'std' : compute the standard deviation within each bin. This
        is implicitly calculated with ddof=0.
      * 'median' : compute the median of values for points within each
        bin. Empty bins will be represented by NaN.
      * 'count' : compute the count of points within each bin.  This is
        identical to an unweighted histogram.  `values` array is not
        referenced.
      * 'sum' : compute the sum of values for points within each bin.
        This is identical to a weighted histogram.
      * 'min' : compute the minimum of values for points within each bin.
        Empty bins will be represented by NaN.
      * 'max' : compute the maximum of values for point within each bin.
        Empty bins will be represented by NaN.
      * function : a user-defined function which takes a 1D array of
        values, and outputs a single numerical statistic. This function
        will be called on the values in each bin.  Empty bins will be
        represented by function([]), or NaN if this returns an error.

bins : int or sequence of scalars, 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.  Values in `x` that are smaller than lowest bin edge are
    assigned to bin number 0, values beyond the highest bin are assigned to
    ``bins[-1]``.  If the bin edges are specified, the number of bins will
    be, (nx = len(bins)-1).
range : (float, float) or [(float, float)], optional
    The lower and upper range of the bins.  If not provided, range
    is simply ``(x.min(), x.max())``.  Values outside the range are
    ignored.

Returns
-------
statistic : array
    The values of the selected statistic in each bin.
bin_edges : array of dtype float
    Return the bin edges ``(length(statistic)+1)``.
binnumber: 1-D ndarray of ints
    Indices of the bins (corresponding to `bin_edges`) in which each value
    of `x` belongs.  Same length as `values`.  A binnumber of `i` means the
    corresponding value is between (bin_edges[i-1], bin_edges[i]).

See Also
--------
numpy.digitize, numpy.histogram, binned_statistic_2d, binned_statistic_dd

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.

.. versionadded:: 0.11.0

Examples
--------
>>> import numpy as np
>>> from scipy import stats
>>> import matplotlib.pyplot as plt

First some basic examples:

Create two evenly spaced bins in the range of the given sample, and sum the
corresponding values in each of those bins:

>>> values = [1.0, 1.0, 2.0, 1.5, 3.0]
>>> stats.binned_statistic([1, 1, 2, 5, 7], values, 'sum', bins=2)
BinnedStatisticResult(statistic=array([4. , 4.5]),
        bin_edges=array([1., 4., 7.]), binnumber=array([1, 1, 1, 2, 2]))

Multiple arrays of values can also be passed.  The statistic is calculated
on each set independently:

>>> values = [[1.0, 1.0, 2.0, 1.5, 3.0], [2.0, 2.0, 4.0, 3.0, 6.0]]
>>> stats.binned_statistic([1, 1, 2, 5, 7], values, 'sum', bins=2)
BinnedStatisticResult(statistic=array([[4. , 4.5],
       [8. , 9. ]]), bin_edges=array([1., 4., 7.]),
       binnumber=array([1, 1, 1, 2, 2]))

>>> stats.binned_statistic([1, 2, 1, 2, 4], np.arange(5), statistic='mean',
...                        bins=3)
BinnedStatisticResult(statistic=array([1., 2., 4.]),
        bin_edges=array([1., 2., 3., 4.]),
        binnumber=array([1, 2, 1, 2, 3]))

As a second example, we now generate some random data of sailing boat speed
as a function of wind speed, and then determine how fast our boat is for
certain wind speeds:

>>> rng = np.random.default_rng()
>>> windspeed = 8 * rng.random(500)
>>> boatspeed = .3 * windspeed**.5 + .2 * rng.random(500)
>>> bin_means, bin_edges, binnumber = stats.binned_statistic(windspeed,
...                 boatspeed, statistic='median', bins=[1,2,3,4,5,6,7])
>>> plt.figure()
>>> plt.plot(windspeed, boatspeed, 'b.', label='raw data')
>>> plt.hlines(bin_means, bin_edges[:-1], bin_edges[1:], colors='g', lw=5,
...            label='binned statistic of data')
>>> plt.legend()

Now we can use ``binnumber`` to select all datapoints with a windspeed
below 1:

>>> low_boatspeed = boatspeed[binnumber == 0]

As a final example, we will use ``bin_edges`` and ``binnumber`` to make a
plot of a distribution that shows the mean and distribution around that
mean per bin, on top of a regular histogram and the probability
distribution function:

>>> x = np.linspace(0, 5, num=500)
>>> x_pdf = stats.maxwell.pdf(x)
>>> samples = stats.maxwell.rvs(size=10000)

>>> bin_means, bin_edges, binnumber = stats.binned_statistic(x, x_pdf,
...         statistic='mean', bins=25)
>>> bin_width = (bin_edges[1] - bin_edges[0])
>>> bin_centers = bin_edges[1:] - bin_width/2

>>> plt.figure()
>>> plt.hist(samples, bins=50, density=True, histtype='stepfilled',
...          alpha=0.2, label='histogram of data')
>>> plt.plot(x, x_pdf, 'r-', label='analytical pdf')
>>> plt.hlines(bin_means, bin_edges[:-1], bin_edges[1:], colors='g', lw=2,
...            label='binned statistic of data')
>>> plt.plot((binnumber - 0.5) * bin_width, x_pdf, 'g.', alpha=0.5)
>>> plt.legend(fontsize=10)
>>> plt.show()

      r   )len	TypeErrornpasarrayfloatr	   r
   )	xvaluesr   binsrangeNmediansedges
binnumberss	            P/var/www/html/venv/lib/python3.13/site-packages/scipy/stats/_binned_statistic.pyr   r      s    xI 	Av

4'(u:?GE!4	
V"-GJ !(J??  s   A$ $A32A3BinnedStatistic2dResult)r   x_edgey_edger   c           	           [        U5      nUS:w  a%  US:w  a  [        R                  " U[        5      =pX/n[        X/X#XEUS9u  pn[        XS   US   U5      $ ! [         a    Sn N\f = f)aU  
Compute a bidimensional binned statistic for one or more sets of data.

This is a generalization of a histogram2d function.  A histogram divides
the space into bins, and returns the count of the number of points in
each bin.  This function allows the computation of the sum, mean, median,
or other statistic of the values (or set of values) within each bin.

Parameters
----------
x : (N,) array_like
    A sequence of values to be binned along the first dimension.
y : (N,) array_like
    A sequence of values to be binned along the second dimension.
values : (N,) array_like or list of (N,) array_like
    The data on which the statistic will be computed.  This must be
    the same shape as `x`, or a list of sequences - each with the same
    shape as `x`.  If `values` is such a list, the statistic will be
    computed on each independently.
statistic : string or callable, optional
    The statistic to compute (default is 'mean').
    The following statistics are available:

      * 'mean' : compute the mean of values for points within each bin.
        Empty bins will be represented by NaN.
      * 'std' : compute the standard deviation within each bin. This
        is implicitly calculated with ddof=0.
      * 'median' : compute the median of values for points within each
        bin. Empty bins will be represented by NaN.
      * 'count' : compute the count of points within each bin.  This is
        identical to an unweighted histogram.  `values` array is not
        referenced.
      * 'sum' : compute the sum of values for points within each bin.
        This is identical to a weighted histogram.
      * 'min' : compute the minimum of values for points within each bin.
        Empty bins will be represented by NaN.
      * 'max' : compute the maximum of values for point within each bin.
        Empty bins will be represented by NaN.
      * function : a user-defined function which takes a 1D array of
        values, and outputs a single numerical statistic. This function
        will be called on the values in each bin.  Empty bins will be
        represented by function([]), or NaN if this returns an error.

bins : int or [int, int] or array_like or [array, array], optional
    The bin specification:

      * the number of bins for the two dimensions (nx = ny = bins),
      * the number of bins in each dimension (nx, ny = bins),
      * the bin edges for the two dimensions (x_edge = y_edge = bins),
      * the bin edges in each dimension (x_edge, y_edge = bins).

    If the bin edges are specified, the number of bins will be,
    (nx = len(x_edge)-1, ny = len(y_edge)-1).

range : (2,2) array_like, optional
    The leftmost and rightmost edges of the bins along each dimension
    (if not specified explicitly in the `bins` parameters):
    [[xmin, xmax], [ymin, ymax]]. All values outside of this range will be
    considered outliers and not tallied in the histogram.
expand_binnumbers : bool, optional
    'False' (default): the returned `binnumber` is a shape (N,) array of
    linearized bin indices.
    'True': the returned `binnumber` is 'unraveled' into a shape (2,N)
    ndarray, where each row gives the bin numbers in the corresponding
    dimension.
    See the `binnumber` returned value, and the `Examples` section.

    .. versionadded:: 0.17.0

Returns
-------
statistic : (nx, ny) ndarray
    The values of the selected statistic in each two-dimensional bin.
x_edge : (nx + 1) ndarray
    The bin edges along the first dimension.
y_edge : (ny + 1) ndarray
    The bin edges along the second dimension.
binnumber : (N,) array of ints or (2,N) ndarray of ints
    This assigns to each element of `sample` an integer that represents the
    bin in which this observation falls.  The representation depends on the
    `expand_binnumbers` argument.  See `Notes` for details.


See Also
--------
numpy.digitize, numpy.histogram2d, binned_statistic, binned_statistic_dd

Notes
-----
Binedges:
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.

`binnumber`:
This returned argument assigns to each element of `sample` an integer that
represents the bin in which it belongs.  The representation depends on the
`expand_binnumbers` argument. If 'False' (default): The returned
`binnumber` is a shape (N,) array of linearized indices mapping each
element of `sample` to its corresponding bin (using row-major ordering).
Note that the returned linearized bin indices are used for an array with
extra bins on the outer binedges to capture values outside of the defined
bin bounds.
If 'True': The returned `binnumber` is a shape (2,N) ndarray where
each row indicates bin placements for each dimension respectively.  In each
dimension, a binnumber of `i` means the corresponding value is between
(D_edge[i-1], D_edge[i]), where 'D' is either 'x' or 'y'.

.. versionadded:: 0.11.0

Examples
--------
>>> from scipy import stats

Calculate the counts with explicit bin-edges:

>>> x = [0.1, 0.1, 0.1, 0.6]
>>> y = [2.1, 2.6, 2.1, 2.1]
>>> binx = [0.0, 0.5, 1.0]
>>> biny = [2.0, 2.5, 3.0]
>>> ret = stats.binned_statistic_2d(x, y, None, 'count', bins=[binx, biny])
>>> ret.statistic
array([[2., 1.],
       [1., 0.]])

The bin in which each sample is placed is given by the `binnumber`
returned parameter.  By default, these are the linearized bin indices:

>>> ret.binnumber
array([5, 6, 5, 9])

The bin indices can also be expanded into separate entries for each
dimension using the `expand_binnumbers` parameter:

>>> ret = stats.binned_statistic_2d(x, y, None, 'count', bins=[binx, biny],
...                                 expand_binnumbers=True)
>>> ret.binnumber
array([[1, 1, 1, 2],
       [1, 2, 1, 1]])

Which shows that the first three elements belong in the xbin 1, and the
fourth into xbin 2; and so on for y.

r   r   )expand_binnumbersr   )r   r   r   r   r   r	   r   )r   yr   r   r   r   r#   r   xedgesyedgesr   r   r   s                r   r   r      s    jI 	Av!q&**T511!4	
4+"-GJ #7!HeAh
KK  s   A A*)A*BinnedStatisticddResultc                 &   [         R                  " U5      (       a_  [         R                  " U [         R                  " U5      5      n[         R                  " U [         R                  " U5      5      nX#S-  -   nU$ [         R                  " X5      nU$ )Ny              ?)r   iscomplexobjbincountrealimag)r   weightsabzs        r   	_bincountr1   m  sj    	wKK2777+,KK2777+,"H H KK#H    c           
         / SQn[        U5      (       d  X';  a  [        SU< 35      e [        U5      n[	        U[
        5      (       a8  [        R                  " U 5      R                  5       (       d  [        U < S35      e U R                  u  p[        R                  " U5      n[        UR                  5      n
[        R                  " U5      nUR                  u  pUS:w  a  X:w  a  [        S5      e [        U5      nX:w  a  [        S5      e Uc  [!        XU5      u  pn[#        XUU5      nOUR$                  n[        R&                  " [(        R*                  " U	5       Vs/ s H  n[        UU   5      S-   PM     sn5      n[(        R*                  " U	5       Vs/ s H  n[        R,                  " UU   5      PM     nnUR.                  n[        R0                  " U[        R2                  5      n[        R4                  " XR7                  5       /US	9nUS
[        R8                  1;   ay  UR;                  [        R<                  5        [?        US5      nURA                  5       n[(        R*                  " U5       H"  n[?        UUU   5      nUU   UU   -  UUU4'   M$     GOUS[        RB                  1;   a  UR;                  [        R<                  5        [?        US5      nURA                  5       n[(        R*                  " U5       Hj  n[?        UUU   5      nUU   UU   UU   -  -
  n[        RD                  " [?        UU[        RF                  " U5      -  5      U   UU   -  5      nUUUU4'   Ml     [        RH                  " U5      nGOUS:X  a  [        R4                  " XR7                  5       /[        R2                  S	9nUR;                  S5        [?        US5      n[        RJ                  " [        U5      5      nU[        RL                  SS24   USS2U4'   GO9US[        RN                  1;   ae  UR;                  S5        [(        R*                  " U5       H8  n[?        UUU   5      n[        RJ                  " [        U5      5      nUUUU4'   M:     GOUS[        RP                  1;   a  UR;                  [        R<                  5        [(        R*                  " U5       H  n[        RR                  " UU   U45      n[        RT                  " UU   SSS9u  nnnUUS-
  S-  -   nUUU4   [        RV                  " U5      RY                  [
        5         nUUU4   [        RZ                  " U5      RY                  [
        5         n UU -   S-  n!U!UUUU   U   4'   M     GOUS[        R\                  1;   al  UR;                  [        R<                  5        [(        R*                  " U5       H1  n[        R^                  " UU   5      SSS2   nUUU4   UUUU   4'   M3     GO.US[        R`                  1;   ae  UR;                  [        R<                  5        [(        R*                  " U5       H+  n[        R^                  " UU   5      nUUU4   UUUU   4'   M-     O[        U5      (       a  [        Rb                  " SS9   [e        5          [g        S[h        5         U" / 5      n"SSS5        SSS5        [        Rl                  " W"5      (       a  URY                  [        Rn                  5      nUR;                  U"5         [q        UUUX5        URs                  [        Rt                  " X5      5      n[w        [y        S5      /U	[y        SS5      /-  -   5      n#UU#   nU(       a1  U	S:  a+  [        R                  " [        Rz                  " UU5      5      n[        R|                  " UR                  SS US-
  :g  5      (       a  [        S5      eURs                  U
SS [        US-
  5      -   5      n[        UUU5      $ ! [         a     GN-f = f! [        [        4 a2    [        R                  " U 5      R                  n U R                  u  p GNf = f! [         a	    X/-  n GNf = fs  snf s  snf ! [j         a    [        R<                  n" GNf = f! , (       d  f       GN= f! , (       d  f       GN= f! [         a1    URY                  [        Rn                  5      n[q        UUUX5         GNf = f)a1  
Compute a multidimensional binned statistic for a set of data.

This is a generalization of a histogramdd function.  A histogram divides
the space into bins, and returns the count of the number of points in
each bin.  This function allows the computation of the sum, mean, median,
or other statistic of the values within each bin.

Parameters
----------
sample : array_like
    Data to histogram passed as a sequence of N arrays of length D, or
    as an (N,D) array.
values : (N,) array_like or list of (N,) array_like
    The data on which the statistic will be computed.  This must be
    the same shape as `sample`, or a list of sequences - each with the
    same shape as `sample`.  If `values` is such a list, the statistic
    will be computed on each independently.
statistic : string or callable, optional
    The statistic to compute (default is 'mean').
    The following statistics are available:

      * 'mean' : compute the mean of values for points within each bin.
        Empty bins will be represented by NaN.
      * 'median' : compute the median of values for points within each
        bin. Empty bins will be represented by NaN.
      * 'count' : compute the count of points within each bin.  This is
        identical to an unweighted histogram.  `values` array is not
        referenced.
      * 'sum' : compute the sum of values for points within each bin.
        This is identical to a weighted histogram.
      * 'std' : compute the standard deviation within each bin. This
        is implicitly calculated with ddof=0. If the number of values
        within a given bin is 0 or 1, the computed standard deviation value
        will be 0 for the bin.
      * 'min' : compute the minimum of values for points within each bin.
        Empty bins will be represented by NaN.
      * 'max' : compute the maximum of values for point within each bin.
        Empty bins will be represented by NaN.
      * function : a user-defined function which takes a 1D array of
        values, and outputs a single numerical statistic. This function
        will be called on the values in each bin.  Empty bins will be
        represented by function([]), or NaN if this returns an error.

bins : sequence or positive int, optional
    The bin specification must be in one of the following forms:

      * A sequence of arrays describing the 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 lower and upper bin edges to be used if the edges are
    not given explicitly in `bins`. Defaults to the minimum and maximum
    values along each dimension.
expand_binnumbers : bool, optional
    'False' (default): the returned `binnumber` is a shape (N,) array of
    linearized bin indices.
    'True': the returned `binnumber` is 'unraveled' into a shape (D,N)
    ndarray, where each row gives the bin numbers in the corresponding
    dimension.
    See the `binnumber` returned value, and the `Examples` section of
    `binned_statistic_2d`.
binned_statistic_result : binnedStatisticddResult
    Result of a previous call to the function in order to reuse bin edges
    and bin numbers with new values and/or a different statistic.
    To reuse bin numbers, `expand_binnumbers` must have been set to False
    (the default)

    .. versionadded:: 0.17.0

Returns
-------
statistic : ndarray, shape(nx1, nx2, nx3,...)
    The values of the selected statistic in each two-dimensional bin.
bin_edges : list of ndarrays
    A list of D arrays describing the (nxi + 1) bin edges for each
    dimension.
binnumber : (N,) array of ints or (D,N) ndarray of ints
    This assigns to each element of `sample` an integer that represents the
    bin in which this observation falls.  The representation depends on the
    `expand_binnumbers` argument.  See `Notes` for details.


See Also
--------
numpy.digitize, numpy.histogramdd, binned_statistic, binned_statistic_2d

Notes
-----
Binedges:
All but the last (righthand-most) bin is half-open in each dimension.  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.

`binnumber`:
This returned argument assigns to each element of `sample` an integer that
represents the bin in which it belongs.  The representation depends on the
`expand_binnumbers` argument. If 'False' (default): The returned
`binnumber` is a shape (N,) array of linearized indices mapping each
element of `sample` to its corresponding bin (using row-major ordering).
If 'True': The returned `binnumber` is a shape (D,N) ndarray where
each row indicates bin placements for each dimension respectively.  In each
dimension, a binnumber of `i` means the corresponding value is between
(bin_edges[D][i-1], bin_edges[D][i]), for each dimension 'D'.

.. versionadded:: 0.11.0

Examples
--------
>>> import numpy as np
>>> from scipy import stats
>>> import matplotlib.pyplot as plt
>>> from mpl_toolkits.mplot3d import Axes3D

Take an array of 600 (x, y) coordinates as an example.
`binned_statistic_dd` can handle arrays of higher dimension `D`. But a plot
of dimension `D+1` is required.

>>> mu = np.array([0., 1.])
>>> sigma = np.array([[1., -0.5],[-0.5, 1.5]])
>>> multinormal = stats.multivariate_normal(mu, sigma)
>>> data = multinormal.rvs(size=600, random_state=235412)
>>> data.shape
(600, 2)

Create bins and count how many arrays fall in each bin:

>>> N = 60
>>> x = np.linspace(-3, 3, N)
>>> y = np.linspace(-3, 4, N)
>>> ret = stats.binned_statistic_dd(data, np.arange(600), bins=[x, y],
...                                 statistic='count')
>>> bincounts = ret.statistic

Set the volume and the location of bars:

>>> dx = x[1] - x[0]
>>> dy = y[1] - y[0]
>>> x, y = np.meshgrid(x[:-1]+dx/2, y[:-1]+dy/2)
>>> z = 0

>>> bincounts = bincounts.ravel()
>>> x = x.ravel()
>>> y = y.ravel()

>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection='3d')
>>> with np.errstate(divide='ignore'):   # silence random axes3d warning
...     ax.bar3d(x, y, z, dx, dy, bincounts)

Reuse bin numbers and bin edges with new values:

>>> ret2 = stats.binned_statistic_dd(data, -np.arange(600),
...                                  binned_statistic_result=ret,
...                                  statistic='mean')
)meanmediancountsumstdminmaxzinvalid statistic z contains non-finite values.r6   zQThe number of `values` elements must match the length of each `sample` dimension.zEThe dimension of bins must be equal to the dimension of the sample x.Nr   dtyper4   r8   r   r7   r5   T)return_indexreturn_countsr   r9   r:   ignore)invalidzInternal Shape Error)Acallable
ValueErrorr   r   
isinstanceintr   isfiniteallshapeAttributeError
atleast_2dTr   listr   
_bin_edges_bin_numbersr   arraybuiltinsr   diffr   result_typefloat64emptyprodr4   fillnanr1   nonzeror8   sqrtconjr+   arangenewaxisr7   r5   lexsortuniquefloorastypeceilr9   argsortr:   errstater   r   RuntimeWarning	Exceptionr)   
complex128_calc_binned_statisticreshapeappendtuplesliceunravel_indexanyRuntimeErrorr'   )$sampler   r   r   r   r#   binned_statistic_resultknown_statsDlenNdiminput_shapeVdimVlenMnbinr   dedgesr   irR   result	flatcountr.   vvflatsumdeltar8   _jcountsmidmid_amid_br   nullcores$                                       r   r	   r	   x  s   @ JKI9#?-i];<<T{ $R[[%8%<%<%>%>F:%ABCC
"\\
 ZZFv||$K]]6"FJD G B C 	CI9  "E F F  &(u=V!&v>
'11xxHNN44HI4HqU1X*4HIJ-5^^D-AB-A"''%(#-AB,66
 ..4KXXtYY[)=FVRWW%%BFFj$/	..&B
F2J7G#AJ15F2q5M ' 
ubffo	%BFFj$/	..&B
F2J7G2J!4y7L!LLE''*eBGGEN&:;A>1MC  F2q5M ' 	g	4-RZZ@Aj$/	IIc)n% Q/q!t	ubffo	%A..&B
F2J7G		#g,'A#F2q5M ' 
x+	+BFF..&B

F2J
34A99Z]26dLLAq&vzQ&&C2q5M"((3-"6"6s";<E2q5M"''#,"5"5c":;Eu})G+2F2z!}Q''( ' 
ubffo	%BFF..&B

6":&tt,A(.r1uF2z!}$% ' 
ubffo	%BFF..&B

6":&A(.r1uF2z!}$% ' 
)		[[*N,<>2 } -=* ??4  ]]2==1FD	"j&& ^^BIId12F %+q"!667DD\F TAXZZ 0 0T BC
	vvfll12$(*++122 ^^K,tDF|;<F"65*==_   J' "v&((\\
d",  f} JB@  vv	 -=,<**  	]]2==1F"j&&	s   a a& 7b+ 'c!#cc> c,2c:c>d 
a#"a#&>b('b(+b>=b>c)%c,(c))c,,
c;	6c>>
d7e
ec                 \   [         R                  " U5      n[        R                  " U 5       H|  n[	        XX65      nU Hg  nU" [         R
                  " Xx   5      5      n	[         R                  " U	5      (       a&  [         R                  " U5      (       d  [        S5      eXXh4'   Mi     M~     g )Nz'The statistic function returns complex )r   r^   rP   r   _create_binned_datarO   r)   rC   )
ru   bin_numbersr{   r   	stat_funcunique_bin_numbersr}   bin_maprz   stats
             r   rg   rg     s    ;/nnT"%k&,2#ARXXgj12Dt$$R__V-D-D !JKK 25M	 $ #r2   c                     [        5       nU H  n/ XE'   M	     [        R                  " [        U 5      5       H  nX@U      R	                  X#U4   5        M     U$ )zWCreate hashmap of bin ids to values in bins
key: bin number
value: list of binned data
)dictrP   r   r   ri   )r   r   r   r}   r   rz   s         r   r   r     sT    
 fG
  ^^C,-A&&v!e}5 .Nr2   c                 ^   U R                   u  p4[        R                  " U[        5      nUS/-  nUS/-  nUcy  [        R                  " [        R
                  " U R                  SS9[        5      5      n[        R                  " [        R
                  " U R                  SS9[        5      5      n	O[        U5      U:w  a  [        S[        U5       SU S35      e[        R                  " U5      n[        R                  " U5      n	[        R                  " U5       H<  n
X*   S   X*   S   :  a  [        SUS:  a	  S	U
S-    S
3OS S35      eX*   u  X'   X'   M>     [        R                  " [        U5      5       H!  n
X   X   :X  d  M  X   S-
  X'   X   S-   X'   M#     [        R                  " U R                  [        R                  5      (       a  U R                  O[        n[        R                  " U5       H  n
[        R                   " X   5      (       a,  X   S-   XZ'   [        R"                  " X   X   XZ   S-
  US9Xj'   O-[        R$                  " X   U5      Xj'   [        Xj   5      S-   XZ'   [        R&                  " Xj   5      Xz'   M     [        R$                  " U5      nXVU4$ )zCreate edge arrays
    Nr   )axiszrange given for z dimensions; z	 requiredr   zIn z
dimension z of  zrange, start must be <= stopg      ?r   r;   )rH   r   rT   rE   
atleast_1drO   r9   r   r:   r   rC   rP   r   
issubdtyper<   floatingisscalarlinspacer   rQ   )ro   r   r   rr   rs   rx   r   ry   sminsmaxrz   edges_dtypes               r   rM   rM     sP    JD88D#DD6METF]F }}}RXXfjjaj&8%@A}}RXXfjjaj&8%@Au:"3u:,mD6KM Mxx~xx~%Ax{UXa[( dQhJq1ugT2BG H- -. .  %xDGTW & ^^CI&7dgglDGglDG ' $&==r{{#K#K6<<  ^^D!;;twgkDG{{47DGTWq[)46EH zz$';7EH%(ma'DGGGEH%	 " ::dDr2   c           	      `   U R                   u  pE[        U5       Vs/ s H#  n[        R                  " U SS2U4   X&   5      PM%     nn[        U5       H  nX6   R	                  5       nUS:X  a  [        S5      e[        [        R                  " U5      * 5      S-   n	[        R                  " U SS2U4   X&   S   :  [        R                  " U SS2U4   U	5      [        R                  " X&   S   U	5      :H  -  5      S   n
Xv   U
==   S-  ss'   M     [        R                  " Xq5      nU$ s  snf )zECompute the bin number each sample falls into, in each dimension
    Nr   z.The smallest edge difference is numerically 0.   r?   r   )rH   r   r   digitizer9   rC   rE   log10wherearoundravel_multi_index)ro   rx   r   ry   rr   rs   rz   sampBin
dedges_mindecimalon_edger   s               r   rN   rN     s&    JD tA 	F1a4L%(+   4[Y]]_
?MNNrxx
++,q0((F1a4LEHRL8IIfQTlG<IIehrlG<=> ??@B 	
7q   %%g4J1s   *D+)r4   
   N)r4   r   NF)r4   r   NFN)NN)rP   warningsr   r   numpyr   operatorr   collectionsr   __all__r
   r   r   r   r'   r1   r	   rg   r   rM   rN    r2   r   <module>r      s     1   ""
 ##:#JL  +1$(k@\ %%>&34 
 17?DbLJ %%>&34 
 39?D04u>p		!
2jr2   