def unique(arr, tolerance=1e-6) -> np.ndarray:
    """Return unique elements in 1D array, within tolerance.

    Parameters
    ----------
    arr : array_like
        Input array. This will be flattened if it is not already 1D.
    tolerance : number (optional)
        The tolerance for uniqueness.

    Returns
    -------
    array
        The sorted unique values.
    """
    arr = sorted(arr.flatten())
    unique = []
    while len(arr) > 0:
        current = arr[0]
        lis = [xi for xi in arr if np.abs(current - xi) < tolerance]
        arr = [xi for xi in arr if not np.abs(lis[0] - xi) < tolerance]
        xi_lis_average = sum(lis) / len(lis)
        unique.append(xi_lis_average)
    return np.array(unique)
def unique ( arr , tolerance = 1e-6 ) -> np . ndarray : arr = sorted ( arr . flatten ( ) ) unique = [ ] while len ( arr ) > 0 : current = arr [ 0 ] lis = [ xi for xi in arr if np . abs ( current - xi ) < tolerance ] arr = [ xi for xi in arr if not np . abs ( lis [ 0 ] - xi ) < tolerance ] xi_lis_average = sum ( lis ) / len ( lis ) unique . append ( xi_lis_average ) return np . array ( unique )
Return unique elements in 1D array, within tolerance.

    Parameters
    ----------
    arr : array_like
        Input array. This will be flattened if it is not already 1D.
    tolerance : number (optional)
        The tolerance for uniqueness.

    Returns
    -------
    array
        The sorted unique values.