0

有没有理由从datetime.datetime数组转换而不指定单位us将日期时间转换为全天?或者这是一个错误?

import numpy as np
import datetime
print(np.array([datetime.datetime(2018, 5, 15, 6, 0),datetime.datetime(2018, 5, 15, 6, 30)]).astype('datetime64[us]'))
print(np.array([datetime.datetime(2018, 5, 15, 6, 0),datetime.datetime(2018, 5, 15, 6, 30)]).astype('datetime64'))

输出

['2018-05-15T06:00:00.000000' '2018-05-15T06:30:00.000000']
['2018-05-15' '2018-05-15']

numpy 版本 1.14.3 和 python 3.6.3

从 numpy 文档中,我看不到 datetime64 的默认单位是天。来自https://docs.scipy.org/doc/numpy-1.14.0/reference/arrays.datetime.html

>>> np.array(['2001-01-01T12:00', '2002-02-03T13:56:03.172'], dtype='datetime64')
array(['2001-01-01T12:00:00.000-0600', '2002-02-03T13:56:03.172-0600'], dtype='datetime64[ms]')
4

0 回答 0