如何将NumPy datetime64转换为long ineteger并返回?
import numpy as np
import datetime
np.datetime64(datetime.datetime.now()).astype(long)
给出值1511975032478959
np.datetime64(np.datetime64(datetime.datetime.now()).astype(long))
给出错误:
ValueError: Converting an integer to a NumPy datetime requires a specified unit
答案 0 :(得分:3)
您需要指定long int的单位(在本例中为微秒)。
np.datetime64(np.datetime64(datetime.datetime.now()).astype(long), 'us')
返回
numpy.datetime64('2017-11-29T17:11:44.638713')
答案 1 :(得分:0)
如图here