U
    ޙe
                     @   s$   d Z ddlZd	ddZd
ddZdS )z	
Medoid.
    N   Fc                 C   s   |dkrf| j dddddf | j  }td||}ttjt|dd}|rV|S | dd|f S |dkr| dddddf |  }td||}ttjt|dd}|r|S | |ddf S td|dS )a  
    Compute the medoid along the specified axis.

    Returns the medoid of the array elements.

    Parameters
    ----------
    a : array_like
        Input array or object that can be converted to an array.
    axis : int
        Axis along which the medoid is computed. The default
        is to compute the median along the last axis of the array.
    indexonly : bool, optional
        If this is set to True, only the index of the medoid is returned.
    Returns
    -------
    medoid : ndarray or int
    r   Nijk,ijk->ijaxisr   axis {} out of bounds)TnpeinsumZargminsumsqrt
IndexErrorformat)ar   	indexonlydiffssumidx r   /lib/python3.8/site-packages/hdmedians/medoid.pymedoid	   s    r   c                 C   s  |dkr| j dddddf | j  }td||}tjt|dd}t| jdd}tj||< t|}|rv|S | dd|f S |dkr
| dddddf |  }td||}tjt|dd}t| jdd}tj||< t|}|r|S | |ddf S t	d
|dS )a/  
    Compute the medoid along the specified axis, omitting
    observations containing NaNs.

    Returns the medoid of the array elements.

    Parameters
    ----------
    a : array_like
        Input array or object that can be converted to an array.
    axis : int
        Axis along which the medoid is computed. The default
        is to compute the median along the last axis of the array.
    indexonly : bool, optional
        If this is set to True, only the index of the medoid is returned.
    Returns
    -------
    medoid : ndarray or int
    r   Nr   r   r   r   )r   r   r	   Znansumr   ZisnananynanZ	nanargminr   r   )r   r   r   r   r   Zdistmaskr   r   r   r   	nanmedoid1   s*    




r   )r   F)r   F)__doc__Znumpyr   r   r   r   r   r   r   <module>   s   
(