The last error tells us that np.datetime objects cannot propagate. Addition has been defined - you can add n timesteps to the date and get a different date. But it does not make sense to multiply the date.
In [1238]: x=np.array([1000],dtype='datetime64[s]') In [1239]: x Out[1239]: array(['1970-01-01T00:16:40'], dtype='datetime64[s]') In [1240]: x[0]*3 ... TypeError: ufunc multiply cannot use operands with types dtype('<M8[s]') and dtype('int32')
Thus, an easy way to create a range of datetime objects is to add a range of timestamps. Here, for example, I use 10 second increments
In [1241]: x[0]+np.arange(0,60,10) Out[1241]: array(['1970-01-01T00:16:40', '1970-01-01T00:16:50', '1970-01-01T00:17:00', '1970-01-01T00:17:10', '1970-01-01T00:17:20', '1970-01-01T00:17:30'], dtype='datetime64[s]')
The error in linspace is the result of her attempt to multiply the start value by 1. , as can be seen from the full error stack:
In [1244]: np.linspace(x[0],x[-1],10) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-1244-6e50603c0c4e> in <module>() ----> 1 np.linspace(x[0],x[-1],10) /usr/lib/python3/dist-packages/numpy/core/function_base.py in linspace(start, stop, num, endpoint, retstep, dtype) 88 89 # Convert float/complex array scalars to float, gh-3504 ---> 90 start = start * 1. 91 stop = stop * 1. 92 TypeError: ufunc multiply cannot use operands with types dtype('<M8[s]') and dtype('float64')
Despite the comment, it looks like it just converts ints to float. In any case, it was not written with datetime64 objects.
user89161's is the way to go if you want to use the linspace syntax, otherwise you can just add the increments of your size to the start date.
arange works with these dates:
In [1256]: np.arange(x[0],x[0]+60,10) Out[1256]: array(['1970-01-01T00:16:40', '1970-01-01T00:16:50', '1970-01-01T00:17:00', '1970-01-01T00:17:10', '1970-01-01T00:17:20', '1970-01-01T00:17:30'], dtype='datetime64[s]')