如何将一组二进制数组中的每个数组与该集合外的数组进行比较

How to compare each array in a set of binary arrays to an array that is outside the set

我有一组数组。我还有一个单独的数组 (T) 来比较集合中的每个数组。我曾尝试使用 SequenceMatcher 来执行此操作,但无法弄清楚如何循环它以便将集合中的每个数组与 T 进行比较。

这是遗传算法的适应度函数。我是 python 的新手,尝试过很多东西。下面的代码可能会让人发笑!

import difflib

parents = set()
while len(parents) < 5:
    a = tuple(np.random.choice([0, 1], size=(10)))
    if a not in parents: parents.add(a) # To make them different
parents = np.array([list(x) for x in parents])

print(pop_sp())

T = tuple(np.random.choice([0, 1], size=(20)))

for i in parents:
    fitness=difflib.SequenceMatcher(None,i,T)
    print(fitness.ratio)

我希望输出是

[[0 0 1 0 0 0 0 1 1 0]  
 [0 0 0 1 1 0 1 0 0 0]  
 [1 0 1 1 1 1 0 0 1 1]  
 [0 0 1 0 0 1 1 0 0 0]  
 [1 1 0 1 1 0 0 1 0 0]] 

以及每个数组与 T 的相似度百分比。
但我得到以下信息:

[[0 0 1 0 0 0 0 1 1 0]  
 [0 0 0 1 1 0 1 0 0 0]  
 [1 0 1 1 1 1 0 0 1 1]  
 [0 0 1 0 0 1 1 0 0 0]  
 [1 1 0 1 1 0 0 1 0 0]] 
<bound method SequenceMatcher.ratio of <difflib.SequenceMatcher object at 0x1c1ea8ec88>>  
<bound method SequenceMatcher.ratio of <difflib.SequenceMatcher object at 0x1c1dff9438>>  
<bound method SequenceMatcher.ratio of <difflib.SequenceMatcher object at 0x1c1ea8ec88>>  
<bound method SequenceMatcher.ratio of <difflib.SequenceMatcher object at 0x1c1dff9438>>  
<bound method SequenceMatcher.ratio of <difflib.SequenceMatcher object at 0x1c1ea8ec88>>

你必须调用适应度函数

for i in parents:
    fitness=difflib.SequenceMatcher(None,i,T)
    ratios = fitness.ratio()
    print(ratios)