python - 元素大于三个或更多列表
问题描述
基于以下列表
l1 = [1,2,3]
l2 = [2,3,4]
l3 = [3,4,2]
我想做一个元素大于比较,使得结果数组中的真值只为真,如果第一个数组中的相应元素大于第二个数组中的元素并且第二个数组中的元素大于第三个数组中的元素。
IE
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]
...
numpynp.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(np.greater(l1,l2), np.greater(l2,l3))
推荐阅读
- sql-server - sql:列索引 0 上的扫描错误,名称“”:不支持扫描,将 driver.Value 类型 int64 存储到 *main.SMSBlast 类型中?
- python - 类型错误:标记列时在“str”和“int”的实例之间不支持“>=”
- python - 尝试编织时python27.def“找不到符号表”
- html - 我似乎无法修复图片和页脚周围的填充
- c++ - 如何更改 C++ 中的第 n 个模板参数?
- dialogflow-es - 是否可以录制音频然后在 Google Assistant 上播放?
- javascript - 无法获取节点中解码的base64数据的值
- c# - 将大数据表复制到 MS Access 表 C#
- r - 无法在 r 3.5.2 中安装汽车包
- .net - Shopify Multipass 与 .net