我仍然是 Python 的初学者。我正在尝试实现一种涉及向量和向量之间的归一化差异的算法。方程为
Sr = 1 - ( || r1 - r2|| / || r1 + r2|| )
A given example gives r1 and r2 as shown below.
r1 = {1 2 3 4 5 6 0 3 3 0 0 0 1 1}
r2 = {4 0 3 0 0 0 1 2 3 5 6 7 8 9}
Sr = 0.2023
公式的分解看起来像这样。
r1-r2 is the subtracting the item1 in r1 to the item1 in r2, subtracting the item2 in r1 to item2 in r2,..., until item-n in r1 and r2.
Let's say M is the total sum of (r1-r2)
M = sum(r1-r2) = sum[(1-4) + (2-0) +...+(1-9)]
||r1 - r2|| = math.sqrt(x)(math.(M, 2))
基本上我可以做所有其他与数学相关的函数,但是我在找到一种有效的方法来计算 M 时遇到问题,我需要从两个列表索引中逐个索引添加/减去数字。任何建议都会很棒。谢谢!