为什么时间增量不能在NumPy中乘/除?

2024-10-01 13:25:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我对NumPy不熟悉,我正在尝试计算一些简单的统计信息,比如median或{}。在

我想探讨的“列”之一是时间差(它的类型是timedelta64NumPy类型),但我不能直接应用那些统计ufuncs

----> 1 age_request.std()

TypeError: ufunc 'divide' not supported for the input types, and the inputs could not be 
safely coerced to any supported types according to the casting rule 'safe'

为什么会这样?

我知道我应该研究Pandas,但首先我想熟悉一下{}。在


Tags: thetonumpy信息类型agerequestnot
1条回答
网友
1楼 · 发布于 2024-10-01 13:25:04

看看documentation for datetime。它列出了可以对timedelta对象执行的操作。划分如下:

t1 = t2 // i

请注意,这会计算底限,并丢弃任何剩余部分。在

据我所知,您只能对timedelta对象执行这些操作。虽然我可能错了,您可以使用numpy操作。在

我建议将timedelta对象转换为微秒,然后进行除法、标准差、中值等操作:

^{pr2}$

(不过,我应该补充说,我不完全确定python可以存储的最大整数值是多少,以及tdMicrosecs是否可以超过它。)

相关问题 更多 >