daytime_in_numpy_demo



In [2]:
import numpy as np


Out[2]:
'2015-10-31'

In [6]:
np.datetime_as_string(nd)
nd = np.datetime64('2015-10-31')
nd


Out[6]:
numpy.datetime64('2015-10-31')

In [7]:
d = datetime.datetime(2016,10,31,10,5,30,500000)
nd = np.datetime64(d)
nd


Out[7]:
numpy.datetime64('2016-10-31T18:05:30.500000+0800')

In [9]:
import datetime as dt
nd.astype(dt.datetime)


Out[9]:
datetime.datetime(2016, 10, 31, 10, 5, 30, 500000)

In [11]:
nd = np.datetime64('2015-10','D')
nd


Out[11]:
numpy.datetime64('2015-10-01')

In [12]:
np.arange('2016-01-01','2016-01-04',dtype='datetime64')


Out[12]:
array(['2016-01-01', '2016-01-02', '2016-01-03'], dtype='datetime64[D]')

In [13]:
np.arange('2016-01-01','2016-11-04',dtype='datetime64[M]')


Out[13]:
array(['2016-01', '2016-02', '2016-03', '2016-04', '2016-05', '2016-06',
       '2016-07', '2016-08', '2016-09', '2016-10'], dtype='datetime64[M]')

In [15]:
np.arange('2016-01-01','2016-03-04',dtype='datetime64[W]')[:10]


Out[15]:
array(['2015-12-31', '2016-01-07', '2016-01-14', '2016-01-21',
       '2016-01-28', '2016-02-04', '2016-02-11', '2016-02-18', '2016-02-25'], dtype='datetime64[W]')