(dist, weights_x, weights_y, p)
Create a weighted distance matrix. For dense data, `weights_x` is a
    column vector, `weights_y` is a 1D array, `dist` is the original distance
    matrix, and the computations exploit array broadcasting. For sparse data,
    all three are 1D arrays. `p` can only be ``numpy.inf``, ``1``, or ``2``.
Create a weighted distance matrix. For dense data, `weights_x` is a
    column vector, `weights_y` is a 1D array, `dist` is the original distance
    matrix, and the computations exploit array broadcasting. For sparse data,
    all three are 1D arrays. `p` can only be ``numpy.inf``, ``1``, or ``2``.
Create a weighted distance matrix . For dense data weights_x is a column vector weights_y is a 1D array dist is the original distance matrix and the computations exploit array broadcasting . For sparse data all three are 1D arrays . p can only be numpy . inf 1 or 2 .
def _weight_filtration(dist, weights_x, weights_y, p):
    """Create a weighted distance matrix. For dense data, `weights_x` is a
    column vector, `weights_y` is a 1D array, `dist` is the original distance
    matrix, and the computations exploit array broadcasting. For sparse data,
    all three are 1D arrays. `p` can only be ``numpy.inf``, ``1``, or ``2``."""
    if p == np.inf:
        return np.maximum(dist, np.maximum(weights_x, weights_y))
    elif p == 1:
        return np.where(dist <= np.abs(weights_x - weights_y) / 2,
                        np.maximum(weights_x, weights_y),
                        dist + (weights_x + weights_y) / 2)
    elif p == 2:
        with np.errstate(divide='ignore', invalid='ignore'):
            return np.where(
                dist <= np.abs(weights_x**2 - weights_y**2)**.5 / 2,
                np.maximum(weights_x, weights_y),
                np.sqrt((dist**2 + ((weights_x + weights_y) / 2)**2) *
                        (dist**2 + ((weights_x - weights_y) / 2)**2)) / dist
                )
    else:
        raise NotImplementedError(f"Weighting not supported for p = {p}")
def _weight_filtration ( dist , weights_x , weights_y , p ) : if p == np . inf : return np . maximum ( dist , np . maximum ( weights_x , weights_y ) ) elif p == 1 : return np . where ( dist <= np . abs ( weights_x - weights_y ) / 2 , np . maximum ( weights_x , weights_y ) , dist + ( weights_x + weights_y ) / 2 ) elif p == 2 : with np . errstate ( divide = 'ignore' , invalid = 'ignore' ) : return np . where ( dist <= np . abs ( weights_x ** 2 - weights_y ** 2 ) ** .5 / 2 , np . maximum ( weights_x , weights_y ) , np . sqrt ( ( dist ** 2 + ( ( weights_x + weights_y ) / 2 ) ** 2 ) * ( dist ** 2 + ( ( weights_x - weights_y ) / 2 ) ** 2 ) ) / dist ) else : raise NotImplementedError ( f"Weighting not supported for p = {p}" )