首页 > 解决方案 > 为什么 numpy int64 不能与 timedelta64 一起使用

问题描述

我想知道为什么在使用numpy.int64with时会出现以下错误numpy.timedelta64

ValueError:无法将对象转换为 NumPy timedelta

例如:

In [10]: np.timedelta64(np.int64(2),'D')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-06ccd44f066c> in <module>()
----> 1 np.timedelta64(np.int64(2),'D')

ValueError: Could not convert object to NumPy timedelta

我的问题的原因:我正在使用scipy.stats.mode并将结果传递给numpy.timedelta64在此期间我执行以下int操作作为修复,但有兴趣找出为什么会发生这种行为:

from scipy.stats import mode
import nump as np
np.timedelta64(int(mode([2,2,3,4,1,1,5,5])[0][0]),'D')

Out[15]: numpy.timedelta64(1,'D')

可能是版本问题?

numpy 版本 = 1.10.4

python版本= 2.7.11(64位)

标签: pythonnumpy

解决方案


推荐阅读