U
    f»{j  ã                   @   s   d dl Zddd„ZdS )é    Nç      @é   c           
      C   s¼   ddl m} tjt| ƒtd�}t|ƒD ]‚}tj | |¡} |dkrPt 	|| ƒ¡}n2|dkrb|| ƒ}n |dkrv|| ƒ }nt
d| ƒ‚||k}t ||gd¡}t |¡s& qªq&t |¡d }	|	S )a  Find outliers based on iterated Z-scoring.

    This procedure compares the absolute z-score against the threshold.
    After excluding local outliers, the comparison is repeated until no
    local outlier is present any more.

    Parameters
    ----------
    X : np.ndarray of float, shape (n_elemenets,)
        The scores for which to find outliers.
    threshold : float
        The value above which a feature is classified as outlier.
    max_iter : int
        The maximum number of iterations.
    tail : {0, 1, -1}
        Whether to search for outliers on both extremes of the z-scores (0),
        or on just the positive (1) or negative (-1) side.

    Returns
    -------
    bad_idx : np.ndarray of int, shape (n_features)
        The outlier indices.
    r   )Úzscore)Zdtypeé   éÿÿÿÿz!Tail parameter %s not recognised.)Zscipy.statsr   ÚnpZzerosÚlenÚboolÚrangeÚmaZmasked_arrayÚabsÚ
ValueErrorÚmaxÚanyÚwhere)
ÚXÚ	thresholdZmax_iterÚtailr   Zmy_maskÚ_Zthis_zZ	local_badZbad_idx© r   úU/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/preprocessing/bads.pyÚ_find_outliers   s"    

r   )r   r   r   )Únumpyr   r   r   r   r   r   Ú<module>   s   