作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我似乎无法让 numpy.digitize 与 datetime64 一起工作:
date_bins = np.array([np.datetime64(datetime.datetime(2014, n, 1), 's') for n in range(1,13)])
np.digitize(date_bins, date_bins)
它给出了以下错误:
TypeError: Cannot cast array data from dtype('<M8[s]') to dtype('float64') according to the rule 'safe'
这是预期的行为吗?
最佳答案
获取 datetime
值的 i8
View :
>>> date_bins_i8 = date_bins.view('i8')
>>> np.digitize(date_bins_i8, date_bins_i8)
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
i8
是 64 位整数数据类型,view
构造数组内存的 View 。
关于python - 使用 datetime64 进行 numpy 数字化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27346248/
我有两个向量: time_vec = np.array([0.2,0.23,0.3,0.4,0.5,...., 28....]) values_vec = np.array([500,200,
有几个软件包可用于数字化折线图,例如GetData Graph Digitizer .但是,对于热图的数字化,我找不到任何软件包或程序。 我想使用 Python 数字化热图(来自 png 或 jpg
我似乎无法让 numpy.digitize 与 datetime64 一起工作: date_bins = np.array([np.datetime64(datetime.datetime(2014,
我是一名优秀的程序员,十分优秀!