from scipy.spatial import distance
from sklearn.metrics.pairwise import manhattan_distances

#################### Pure python ###################################
def get_manhattan_distance(p, q):
  
    # sum of absolute difference between coordinates
    distance = 0
    for p_i,q_i in zip(p,q):
        distance += abs(p_i - q_i)
    
    return distance

# check the function
a = (1, 1)
b = (4, 3)
# distance between a and b
d = get_manhattan_distance(a, b)
# display the result
print(d)
print()
########################## using scipy library ########################
# two points in pairs using zip()
a = (1, 0, 2, 3)
b = (4, 4, 3, 1)
# mahattan distance between a and b
d = distance.cityblock(a, b)
# display the result
print(d)
print()
################# using sklearn library ##################
print(manhattan_distances([[3]], [[3]]))
print()
print(manhattan_distances([[3]], [[2]]))
print()
print(manhattan_distances([[2]], [[3]]))
print()
print(manhattan_distances([[1, 2], [3, 4]],
                          [[1, 2], [0, 3]]))

