python - 为什么 numpy int64 不能与 timedelta64 一起使用
问题描述
我想知道为什么在使用numpy.int64
with时会出现以下错误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位)
解决方案
推荐阅读
- apache-spark - 将一个表中的键映射到另一个表中的值
- jquery - 如何获取按钮功能的“数据名称”属性?
- c# - 如何在将应用于水晶报表的 Web 表单上设置范围参数?
- angularjs - 尝试使用两个不同的数组用 ng-repeat 填充 html 表
- python - 使用 opencv 的 minAreaRect() 校正 MNIST 数据集图像
- firebase - 在使用 firebase 创建新帐户时更改个人资料
- visual-studio-code - 编写 VS Code 扩展时如何聚焦自定义视图?
- python - 连接到特定wifi时如何打开特定文件?
- post - 处理来自移动应用程序的流数据(通过 POST)
- c# - C# - 从 JSON 字符串结果提供 ViewModel