向量的逐项控制
Entry-wise domination of vectors
我在 [0,1] 中有几个大小相同的实数列表。例如:
[0.33, 0.0, 0.0, 0.33, 0.33, 0.33, 0.0]
[0.0, 0.33, 0.0, 0.33, 0.33, 0.33, 0.0]
[0.0, 0.33, 0.0, 0.33, 0.0, 0.33, 0.0]
我怀疑有些榜单被其他榜单严格控制;例如,第三个列表由第二个列表控制;在 l3[i] <= l2[i] 对于所有 i 的意义上; l3[j] < l2[j] 对于至少一个 j。
我想摆脱那些;所以我写了这两个函数:
# R correspond to the original list of lists.
# Rp is the list where the striclty dominated lists have been removed.
def minor_solution(r, R):
"""determines if there exists r2 in R such that r <= r2 for all value and r<r2 for at least one value"""
for r2 in R:
if strict_domination(r, r2):
return True
return False
def strict_domination(r1,r2):
"""return true iff r1 is stricly dominated by r2."""
strict = False
dom = True
for i in range(len(r1)):
strict = strict or (r1[i] < r2[i])
dom = dom and (r1[i] <= r2[i])
return dom and strict
Rp = []
for ri in R:
if minor_solution(ri, R) == False:
Rp.append(ri)
我的问题是这不起作用。一些列表最终被删除;但一些应该被删除的仍然存在。例如;我给出的示例中的第三个列表没有被删除。有什么想法吗?
对于这样的比较,您不需要遍历所有元素,像这样检查元素就足够了:
l1 = [0,2,5]
l2 = [0,2,5]
l1==l2
True
or
l1 = [0,2,5]
l2 = [0,2,10]
l1<l2
True
和 python 将为您完成 element-wise 的工作。这是我的问题,你需要一个“适者生存”,最主要的list还是其他什么,因为从你给的描述中,不清楚什么关系剩下的list-elements应该是。也许您希望收到的更详尽的示例会有所帮助。
我在 [0,1] 中有几个大小相同的实数列表。例如:
[0.33, 0.0, 0.0, 0.33, 0.33, 0.33, 0.0]
[0.0, 0.33, 0.0, 0.33, 0.33, 0.33, 0.0]
[0.0, 0.33, 0.0, 0.33, 0.0, 0.33, 0.0]
我怀疑有些榜单被其他榜单严格控制;例如,第三个列表由第二个列表控制;在 l3[i] <= l2[i] 对于所有 i 的意义上; l3[j] < l2[j] 对于至少一个 j。 我想摆脱那些;所以我写了这两个函数:
# R correspond to the original list of lists.
# Rp is the list where the striclty dominated lists have been removed.
def minor_solution(r, R):
"""determines if there exists r2 in R such that r <= r2 for all value and r<r2 for at least one value"""
for r2 in R:
if strict_domination(r, r2):
return True
return False
def strict_domination(r1,r2):
"""return true iff r1 is stricly dominated by r2."""
strict = False
dom = True
for i in range(len(r1)):
strict = strict or (r1[i] < r2[i])
dom = dom and (r1[i] <= r2[i])
return dom and strict
Rp = []
for ri in R:
if minor_solution(ri, R) == False:
Rp.append(ri)
我的问题是这不起作用。一些列表最终被删除;但一些应该被删除的仍然存在。例如;我给出的示例中的第三个列表没有被删除。有什么想法吗?
对于这样的比较,您不需要遍历所有元素,像这样检查元素就足够了:
l1 = [0,2,5]
l2 = [0,2,5]
l1==l2
True
or
l1 = [0,2,5]
l2 = [0,2,10]
l1<l2
True
和 python 将为您完成 element-wise 的工作。这是我的问题,你需要一个“适者生存”,最主要的list还是其他什么,因为从你给的描述中,不清楚什么关系剩下的list-elements应该是。也许您希望收到的更详尽的示例会有所帮助。