gpt4 book ai didi

python - 倒数

转载 作者:太空宇宙 更新时间:2023-11-04 07:24:43 27 4
gpt4 key购买 nike

我有一个这样组织的列表:

[('down', 0.0098000000000000309), 
('up', 0.0015000000000000568),
('down', 0.008900000000000019),
('down', 0.023300000000000098),
('down', 0.011599999999999944),
('down', 0.0027000000000000357),
('up', 0.0023999999999999577),
('up', 0.0065000000000000613),
('down', 0.0057000000000000384),
('down', 0.018400000000000083),
('up', 0.009300000000000086),
('down', 0.0038000000000000256),
('down', 0.00050000000000005596),
('up', 0.0082000000000000961), .....

“向后比较”的最佳方式是什么? ,基本上我想返回"is"(或其他什么......)如果我们有一系列的 2 个“下降”然后是一个“上升”并且第二个值低于 0.0095。

我希望他说得有道理..

最佳答案

创建一个滑动窗口,并对其进行测试:

def slidingwindow(iterable):
iterator = iter(iterable)
first, second = iterator.next(), iterator.next()
for next in iterator:
yield (first, second, next)
first, second = second, next

def testforcondition(data):
for window in slidingwindow(data):
direction = [w[0] for w in window]
if direction == ['down', 'down', 'up'] and window[2][1] < 0.0095:
return True
return False

关于python - 倒数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6136716/

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