def manhattan_distances(X, Y):
 if (X is Y):
  X = Y = np.asanyarray(X)
 else:
  X = np.asanyarray(X)
  Y = np.asanyarray(Y)
 if (X.shape[1] != Y.shape[1]):
  raise ValueError('Incompatible dimension for X and Y matrices')
 XY = ssd.cdist(X, Y, 'cityblock')
 return (1.0 - (XY / float(X.shape[1])))

def manhattan_distances ( X , Y ) : if ( X is Y ) : X = Y = np . asanyarray ( X ) else : X = np . asanyarray ( X ) Y = np . asanyarray ( Y ) if ( X . shape [ 1 ] != Y . shape [ 1 ] ) : raise ValueError ( 'Incompatible dimension for X and Y matrices' ) XY = ssd . cdist ( X , Y , 'cityblock' ) return ( 1.0 - ( XY / float ( X . shape [ 1 ] ) ) )
considering the rows of x as vectors .