#NEWLINE# def manhattan_distances( X , Y = None , sum_over_features = True , size_threshold = 500000000.0 ) : #NEWLINE# #INDENT# ' Compute the L1 distances between the vectors in X and Y.\n\n    With sum_over_features equal to False it returns the componentwise\n    distances.\n\n    Read more in the :ref:`User Guide <metrics>`.\n\n    Parameters\n    ----------\n    X : array_like\n        An array with shape (n_samples_X, n_features).\n\n    Y : array_like, optional\n        An array with shape (n_samples_Y, n_features).\n\n    sum_over_features : bool, default=True\n        If True the function returns the pairwise distance matrix\n        else it returns the componentwise L1 pairwise-distances.\n        Not supported for sparse matrix inputs.\n\n    size_threshold : int, default=5e8\n        Unused parameter.\n\n    Returns\n    -------\n    D : array\n        If sum_over_features is False shape is\n        (n_samples_X * n_samples_Y, n_features) and D contains the\n        componentwise L1 pairwise-distances (ie. absolute difference),\n        else shape is (n_samples_X, n_samples_Y) and D contains\n        the pairwise L1 distances.\n\n    Examples\n    --------\n    >>> from sklearn.metrics.pairwise import manhattan_distances\n    >>> manhattan_distances([[3]], [[3]])#doctest:+ELLIPSIS\n    array([[ 0.]])\n    >>> manhattan_distances([[3]], [[2]])#doctest:+ELLIPSIS\n    array([[ 1.]])\n    >>> manhattan_distances([[2]], [[3]])#doctest:+ELLIPSIS\n    array([[ 1.]])\n    >>> manhattan_distances([[1, 2], [3, 4]],         [[1, 2], [0, 3]])#doctest:+ELLIPSIS\n    array([[ 0.,  2.],\n           [ 4.,  4.]])\n    >>> import numpy as np\n    >>> X = np.ones((1, 2))\n    >>> y = 2 * np.ones((2, 2))\n    >>> manhattan_distances(X, y, sum_over_features=False)#doctest:+ELLIPSIS\n    array([[ 1.,  1.],\n           [ 1.,  1.]]...)\n    ' #NEWLINE# ( X , Y ) = check_pairwise_arrays ( X , Y ) #NEWLINE# if ( issparse ( X ) or issparse ( Y ) ) : #NEWLINE# #INDENT# if ( not sum_over_features ) : #NEWLINE# #INDENT# raise TypeError ( ( 'sum_over_features=%r not supported for sparse matrices' % sum_over_features ) ) #NEWLINE# #UNINDENT# X = csr_matrix ( X , copy = False ) #NEWLINE# Y = csr_matrix ( Y , copy = False ) #NEWLINE# D = np . zeros ( ( X . shape [ 0 ] , Y . shape [ 0 ] ) ) #NEWLINE# _sparse_manhattan ( X . data , X . indices , X . indptr , Y . data , Y . indices , Y . indptr , X . shape [ 1 ] , D ) #NEWLINE# return D #NEWLINE# #UNINDENT# if sum_over_features : #NEWLINE# #INDENT# return distance . cdist ( X , Y , 'cityblock' ) #NEWLINE# #UNINDENT# D = ( X [ : , np . newaxis , : ] - D [ np . newaxis , : , : ] ) #NEWLINE# D = np . abs ( D , D ) #NEWLINE# return D . reshape ( ( ( - 1 ) , X . shape [ 1 ] ) )