gpt4 book ai didi

python - 三个或更多列表的元素大于

转载 作者:行者123 更新时间:2023-12-02 19:49:52 27 4
gpt4 key购买 nike

基于以下列表

l1 = [1,2,3]
l2 = [2,3,4]
l3 = [3,4,2]

我想做一个元素大于比较,这样结果数组中的真值才为真,当且仅当第一个数组中的相应元素大于第二个数组中的元素并且第二个数组中的元素是大于第三个数组中的元素。

print(elementwise_greather_than(l3,l2,l1))
[True,True,False]
print(elementwise_greather_than(l2,l1,l3))
[False,False,True]
print(elementwise_greather_than(l1,l3,l2))
[False,False,False]
...

numpy 的 np.greater 似乎仅适用于两个列表

import numpy as np
print(np.greater(l1,l3))
[False False True]

但不包括 3:

print(np.greater(l1,l3,l2))
TypeError: return arrays must be of ArrayType

假设列表长度相等,我该如何进行比较?

最佳答案

尝试numpy.logical_and :

numpy.logical_and(np.greater(l1,l2), np.greater(l2,l3))

关于python - 三个或更多列表的元素大于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60360899/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com