Some numpy that could help you write code for normalizing a histogram and for computing L1 or L2 distance between histograms. 1. let's see how to normalize a histogram >>> hist = np.array([60,40,33,65,45]) >>> hist array([60, 40, 33, 65, 45]) >>> histnorm = hist / sum(hist) >>> histnorm array([0.24691358, 0.16460905, 0.13580247, 0.26748971, 0.18518519]) >>> sum(histnorm) 1.0 >>> 2. let's see some other math we can do to numpy arrays Suppose we already have 2 histograms that are normalized: >>> hist1 = np.array([0.5,0.3,0.05,0.15]) >>> sum(hist1) 1.0 >>> hist2 = np.array([0.3,0.1,0.4,0.2]) >>> sum(hist2) 1.0 How could we get the L1 distance between them? We could loop through and add up the abs value of the differences of each corresponding element or we could simply do: >>> hist1 - hist2 array([ 0.2 , 0.2 , -0.35, -0.05]) >>> abs(hist1 - hist2) array([0.2 , 0.2 , 0.35, 0.05]) >>> sum(abs(hist1 - hist2)) 0.8 How about L2? We could loop through and add up the squares of the differences of each corresponding element and then take the square root, or we could simply do: >>> pow(2,5) 32 >>> sqrt(2) Traceback (most recent call last): File "", line 1, in NameError: name 'sqrt' is not defined >>> import math >>> math.sqrt(2) 1.4142135623730951 >>> pow(hist1 - hist2, 2) array([0.04 , 0.04 , 0.1225, 0.0025]) >>> sum(pow(hist1 - hist2, 2)) 0.20500000000000002 >>> math.sqrt(sum(pow(hist1 - hist2, 2))) 0.45276925690687087 >>>