Inq*_*tor 3 python datetime numpy
如何将 NumPy datetime64 转换为长整数并返回?
import numpy as np
import datetime
np.datetime64(datetime.datetime.now()).astype(long)
Run Code Online (Sandbox Code Playgroud)
给出值 1511975032478959
np.datetime64(np.datetime64(datetime.datetime.now()).astype(long))
Run Code Online (Sandbox Code Playgroud)
给出一个错误:
ValueError: Converting an integer to a NumPy datetime requires a specified unit
Run Code Online (Sandbox Code Playgroud)
您需要指定 long int 的单位(在本例中为微秒)。
np.datetime64(np.datetime64(datetime.datetime.now()).astype(long), 'us')
Run Code Online (Sandbox Code Playgroud)
返回
numpy.datetime64('2017-11-29T17:11:44.638713')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9629 次 |
| 最近记录: |