
    0Ph	                     "    d dl ZddlmZ ddZdS )    N   )stable_cumsum2   c                 ~  
 | j         }|dk    r| d         S | j         dk    r|                     d          } | j        |j        k    rC| j        d         |j        d         k    r't          j        || j        d         df          j        }t          j        | d          }t          j        ||d          }t          |d          |dz  d         z  

dk    }t          j	        
|         
|         dz             
|<   t          j
        
fdt          j        d                   D                       }t          j
        |          }|j        d         dz
  t          j        fd	d|
          }t          j        | j        d                   }|||f         }	| |	|f         }|dk    r|d         n|S )a  Compute weighted percentile

    Computes lower weighted percentile. If `array` is a 2D array, the
    `percentile` is computed along the axis 0.

        .. versionchanged:: 0.24
            Accepts 2D `array`.

    Parameters
    ----------
    array : 1D or 2D array
        Values to take the weighted percentile of.

    sample_weight: 1D or 2D array
        Weights for each value in `array`. Must be same shape as `array` or
        of shape `(array.shape[0],)`.

    percentile: int or float, default=50
        Percentile to compute. Must be value between 0 and 100.

    Returns
    -------
    percentile : int if `array` 1D, ndarray if `array` 2D
        Weighted percentile.
    r    r   )r   )axisd   r   c                 Z    g | ]'}t          j        d d |f         |                   (S )N)npsearchsorted).0iadjusted_percentile
weight_cdfs     S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/utils/stats.py
<listcomp>z(_weighted_percentile.<locals>.<listcomp>9   sH     	
 	
 	
 OJqqq!t,.A!.DEE	
 	
 	
    c                 0    t          j        | d          S )Nr   )r   clip)xmax_idxs    r   <lambda>z&_weighted_percentile.<locals>.<lambda>B   s    "'!Q(( r   )r	   arr)ndimreshapeshaper   tileTargsorttake_along_axisr   	nextafterarrayrangeapply_along_axisarange)r#   sample_weight
percentilen_dim
sorted_idxsorted_weightsmaskpercentile_idx	col_indexpercentile_in_sortedr   r   r   s             @@@r   _weighted_percentiler0   	   s   4 JEzzRyzQg&&{m)))ek!n@STU@V.V.VA/BCCEE***J'zJJJN ~A666J$s*Z^; !#D "D!#6t#<q#@! ! X	
 	
 	
 	
 	
:+A.//	
 	
 	
 N Xn--Nq!A%G(((((qn  N 	%+a.))I%ni&?@+Y67J!QJJ:a==J6r   )r   )numpyr   extmathr   r0   r   r   r   <module>r3      sC        " " " " " "?7 ?7 ?7 ?7 ?7 ?7r   