Reputation: 1490
I have tried:
import numpy as np
t = np.full((10),'2012-12-10', dtype=np.datetime64)
But got such an error:
ValueError: Cannot create a NumPy datetime other than NaT with generic units
Do you have any idea? Thanks!
Upvotes: 0
Views: 133
Reputation: 380
EDIT: I figured it out, you must fully specify the datatype for datetime objects
Do this
np.full((10), '2012-12-10', dtype='datetime64[D]')
array(['2012-12-10', '2012-12-10', '2012-12-10', '2012-12-10',
'2012-12-10', '2012-12-10', '2012-12-10', '2012-12-10',
'2012-12-10', '2012-12-10'], dtype='datetime64[D]')
My previous answer is below
Hm, not sure why np.full does not work in that case specifically. However one way to achieve this is to instead use np.tile
np.tile(np.array(['2012-12-10'], dtype=np.datetime64), 10)
array(['2012-12-10', '2012-12-10', '2012-12-10', '2012-12-10',
'2012-12-10', '2012-12-10', '2012-12-10', '2012-12-10',
'2012-12-10', '2012-12-10'], dtype='datetime64[D]')
Upvotes: 1