gpt4 book ai didi

Average of datetime.datetime.now() is overstated(Datetime.Datetime.now()的平均值被夸大了)

转载 作者:bug小助手 更新时间:2023-10-24 19:32:29 28 4
gpt4 key购买 nike



If I make a list of time deltas, the average is larger than if I average the microsecond values from these deltas. Why is that?

如果我列一个时间增量的列表,平均值比我对这些增量的微秒值求平均时要大。为什么会这样呢?


import time
import numpy as np
l = []
l_m = []
for _ in range(5):
start = datetime.datetime.now()
time.sleep(1)
l.append((datetime.datetime.now() - start))
l_m.append((datetime.datetime.now() - start).microseconds / 1000000)
print(l)
print(np.mean(l), np.mean(l_m))

gives

赠送


[datetime.timedelta(seconds=1, microseconds=846), datetime.timedelta(seconds=1, microseconds=1017), datetime.timedelta(seconds=1, microseconds=1010), datetime.timedelta(seconds=1, microseconds=1013), datetime.timedelta(seconds=1, microseconds=887)]
0:00:01.000955 0.9639999999999999

This is Python 3.8.10 on Linux.

这是Linux上的Python3.8.10。


更多回答

.microseconds only gets the microseconds part of the delta, which does not include the seconds nor minutes nor anything else…

…仅获取增量的微秒部分,不包括秒、分钟或任何其他微秒

优秀答案推荐

Reading the docs, I see that ‘timedelta’ objects can be added. It can also be divided by a scalar so the average of the ‘timedelta’ is correct.

阅读文档后,我发现‘time Delta’对象可以添加。它还可以被标量除以,因此‘time Delta’的平均值是正确的。


Thanks to the comments, I see that the ‘microsecond’ attribute is just the microsecond portion of the ‘timedelta’ and does not include other components such as the seconds values.

多亏了这些评论,我看到‘micro秒’属性只是‘time Delta’的微秒部分,不包括其他组件,如秒值。


更多回答

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