Issue
I have a numpy array x
of dtype np.int64
representing nanoseconds. I'm able to convert this into a numpy array of dtype np.datetime64
with the following code:
np.array([np.datetime64(int(a), 'ns') for a in x])
Is there a better way to do this, that avoids python list comprehension?
Solution
You can do:
x = np.array([1e9, 5e9, 1e10], dtype=np.int64)
x.astype('datetime64[ns]')
Output:
array(['1970-01-01T00:00:01.000000000', '1970-01-01T00:00:05.000000000',
'1970-01-01T00:00:10.000000000'], dtype='datetime64[ns]')
Answered By - Quang Hoang
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.