Distance similarity between two lists

Viewed 164

I am trying to find out the similarity score between two lists using L1 Norm. It should be between first array of first list and first array of second list, second array of first list and second array of second list and so on ( as I have a big list). For example, two lists are as follows:

import numpy as np
from numpy import array

features1 = [array([0.02665389, 0.06815204, 0.14547031]), array([0, 0.00247839, 0.04664821, 0.5, 0.7]) ]
features2 = [array([0.02552605, 0.07776146, 0.18030827]), array([0.00000000e+00, 3.80687169e-03, 9.15574149e-02,0.5, 0.7])]

I'm not sure how I can compute the distance score, as the lists are unequal. I tried using numpy but I get broadcast error.

dist= np.max(np.sum(np.abs(np.subtract(features1,features2))))
print(dist)
ValueError: operands could not be broadcast together with shapes (3,) (5,)
1 Answers
import numpy as np
from numpy import array

features1 = [array([0.02665389, 0.06815204, 0.14547031]), array([0, 0.00247839, 0.04664821, 0.5, 0.7]) ]
features2 = [array([0.02552605, 0.07776146, 0.18030827]), array([0.00000000e+00, 3.80687169e-03, 9.15574149e-02,0.5, 0.7])]

for i, elem in enumerate(features1):
    try:
        dist= np.max(np.sum(np.abs(np.subtract(features1[i],features2[i]))))
        print(dist)
    except:
        print("Lists might not be of identical length")
Related