Python 映射中的函数仅检测一个参数

Python 映射中的函数仅检测一个参数,python,itertools,Python,Itertools,我想计算两个集合中所有元素组合之间的距离 描述符_1(resp.描述符_2)是长度为N1(resp.N2)的二维数组列表(每个元素一个二维数组) 要计算这两个集合之间的所有组合,我使用: combi = list(itertools.product(descriptor_1, descriptor_2)) 这将产生一个长度为2倍的列表N1*N2 要计算距离: dist = map(chi2_dist, combi) 其中: def chi2_dist(a, b): a = a.fla

我想计算两个集合中所有元素组合之间的距离

描述符_1
(resp.
描述符_2
)是长度为N1(resp.N2)的二维数组列表(每个元素一个二维数组)

要计算这两个集合之间的所有组合,我使用:

combi = list(itertools.product(descriptor_1, descriptor_2))
这将产生一个长度为2倍的列表
N1*N2

要计算距离:

dist = map(chi2_dist, combi)
其中:

def chi2_dist(a, b):
    a = a.flatten()
    b = b.flatten()

    dist = (1/2) * np.sum( (a-b)**2 / (a+b+EPS))

    return dist
但是,我得到以下错误:

TypeError: chi2_dist() takes exactly 2 arguments (1 given)

但是,由于我的元组包含2个元素,我不理解错误。

您的功能应该是

def chi2_dist(ab):
    a = ab[0]
    b = ab[1]
    a = a.flatten()
    b = b.flatten()
顺便说一句,更有效的只是

map(chi2_dist, itertools.product(descriptor_1, descriptor_2))

不需要中间列表

您的功能应该是

def chi2_dist(ab):
    a = ab[0]
    b = ab[1]
    a = a.flatten()
    b = b.flatten()
顺便说一句,更有效的只是

map(chi2_dist, itertools.product(descriptor_1, descriptor_2))

不需要中间列表

您可以发布列表组合的输出吗?您希望
map
自动解压缩元组,但如果它真的按照您的预期实现,那些真正想要传递元组的用户呢?你能发布列表的输出吗?你希望
map
自动解压你的元组,但是如果它真的按照你的期望实现,那么真正想要传递元组的用户呢?