[Python] Cosine Similarity between 2 Number Lists

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I want to calculate the cosine similarity between two lists, let's say for example list 1 which is dataSetI and list 2 which is dataSetII.

    Let's say dataSetI is [3, 45, 7, 2] and dataSetII is [2, 54, 13, 15]. The length of the lists are always equal. I want to report cosine similarity as a number between 0 and 1.

    dataSetI = [3, 45, 7, 2]
    dataSetII = [2, 54, 13, 15]

    def cosine_similarity(list1, list2):
    # How to?
    pass

    print(cosine_similarity(dataSetI, dataSetII))

    Continue reading...

Compartilhe esta Página