scores = [2.619, 3.3, 9.67, 0.1, 6.7, 3.2]
min_score_thresh = 5
# score is 5 or higher
result = []
# position in 'scores' list
indx = []
for i, item in enumerate(scores):
if item > min_score_thresh:
result.append(item)
indx.append(i)
x = indx
print(result)
print(x)
通过列表理解获取索引(或值)很容易:
我们可以得到这两个,作为元组的列表:
^{pr2}$然后我们可以使用
zip*
习惯用法来“转置”此列表:或者在一个表达式中使用unpacking来包装:
乍一看,从一个列表理解中获取几个列表是很困难的,但是这个zip*转换可以解决这个问题。在
将
numpy.where
用于矢量化解决方案:相关问题 更多 >
编程相关推荐