(x, y)
return result, grad
r"""Manhattan, taxicab, or l1 distance with gradient.

    ..math::
        D(x, y) = \sum_i |x_i - y_i|
r"""Manhattan, taxicab, or l1 distance with gradient.
r Manhattan taxicab or l1 distance with gradient .
def manhattan_grad(x, y):
    r"""Manhattan, taxicab, or l1 distance with gradient.

    ..math::
        D(x, y) = \sum_i |x_i - y_i|
    """
    result = 0.0
    grad = np.zeros(x.shape)
    for i in range(x.shape[0]):
        result += np.abs(x[i] - y[i])
        grad[i] = np.sign(x[i] - y[i])
    return result, grad
def manhattan_grad ( x , y ) : result = 0.0 grad = np . zeros ( x . shape ) for i in range ( x . shape [ 0 ] ) : result += np . abs ( x [ i ] - y [ i ] ) grad [ i ] = np . sign ( x [ i ] - y [ i ] ) return result , grad