2016-01-22 81 views

回答

0

請看這是否是您要查找的轉換類型:從numpy ndarray到datetime,字符串或numpy日期時間:

import datetime as dt 
import numpy as np 

x = np.array([[ 2016., 1., 1.], [ 2016., 12., 31.]]) 

string = [dt.datetime(*el).strftime('%Y-%m-%d') for el in x.astype(int)] 
string 
['2016-01-01', '2016-12-31'] 

datetime = np.array(datetime, dtype='datetime64[D]') 
datetime 
array(['2016-01-01', '2016-12-31'], dtype='datetime64[D]') 
相關問題