我试过了:
import numpy as np
t = np.full((10),'2012-12-10', dtype=np.datetime64)
但是出现了这样的错误:
ValueError: Cannot create a NumPy datetime other than NaT with generic units
你知道吗?谢谢!
答案 0 :(得分:1)
编辑:我想通了,你必须完全指定datetime对象的数据类型
这样做
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]')
我以前的答案在下面
嗯,不知道为什么np.full在这种情况下不起作用。但是,实现此目的的一种方法是改为使用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]')