I'm migrating from Matlab... Using Jupyter Lab in Windows 10.
Let's say I have a time series, with an array of datetime64 and some other data
t = np.arange('2010-09-01','2010-09-02', dtype='datetime64[6h]')
d = np.linspace(0,1,len(t))
I want to merge both to save an continue working in another notebook (I know there are other ways to do this!). First I transform them in columns arrays
t_col = t.reshape(-1,1)
d_col = d.reshape(-1,1)
and merge
m = np.c_[t_col, d_col]
and get
TypeError Traceback (most recent call last)
<ipython-input-28-5bbb5e23249f> in <module>
----> 1 m = np.c_[t_col, d_col]
c:\Python37_32\lib\site-packages\numpy\lib\index_tricks.py in __getitem__(self, key)
333 objs[k] = objs[k].astype(final_dtype)
334
--> 335 res = self.concatenate(tuple(objs), axis=axis)
336
337 if matrix:
TypeError: invalid type promotion
but if I first covert the datetime64 to datetime
t_col2 =t_col.astype('datetime64[h]').tolist()
m = np.c_[t_col2, d_col]
it works.
Question: Why I can't merge the arrays when the data&time is datetime64? Why do I need to convert it to datetime?