0

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!

1 Answer 1

1

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]')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.