(x, y, w=_mock_ones, p=2)
return result ** (1.0 / p), grad
r"""A weighted version of Minkowski distance with gradient.

    ..math::
        D(x, y) = \left(\sum_i w_i |x_i - y_i|^p\right)^{\frac{1}{p}}

    If weights w_i are inverse standard deviations of data in each dimension
    then this represented a standardised Minkowski distance (and is
    equivalent to standardised Euclidean distance for p=1).
r"""A weighted version of Minkowski distance with gradient.
r A weighted version of Minkowski distance with gradient .
def weighted_minkowski_grad(x, y, w=_mock_ones, p=2):
    r"""A weighted version of Minkowski distance with gradient.

    ..math::
        D(x, y) = \left(\sum_i w_i |x_i - y_i|^p\right)^{\frac{1}{p}}

    If weights w_i are inverse standard deviations of data in each dimension
    then this represented a standardised Minkowski distance (and is
    equivalent to standardised Euclidean distance for p=1).
    """
    result = 0.0
    for i in range(x.shape[0]):
        result += (w[i] * np.abs(x[i] - y[i])) ** p

    grad = np.empty(x.shape[0], dtype=np.float32)
    for i in range(x.shape[0]):
        grad[i] = (
            w[i] ** p
            * pow(np.abs(x[i] - y[i]), (p - 1.0))
            * sign(x[i] - y[i])
            * pow(result, (1.0 / (p - 1)))
        )

    return result ** (1.0 / p), grad
def weighted_minkowski_grad ( x , y , w = _mock_ones , p = 2 ) : result = 0.0 for i in range ( x . shape [ 0 ] ) : result += ( w [ i ] * np . abs ( x [ i ] - y [ i ] ) ) ** p grad = np . empty ( x . shape [ 0 ] , dtype = np . float32 ) for i in range ( x . shape [ 0 ] ) : grad [ i ] = ( w [ i ] ** p * pow ( np . abs ( x [ i ] - y [ i ] ) , ( p - 1.0 ) ) * sign ( x [ i ] - y [ i ] ) * pow ( result , ( 1.0 / ( p - 1 ) ) ) ) return result ** ( 1.0 / p ) , grad