Consider two pd.Series()
, t
and T
, where:
>>> print(t)
0 2006-04-17 00:00:00
1 2006-04-18 00:00:00
2 2006-04-19 00:00:00
3 2006-04-20 00:00:00
4 2006-04-21 00:00:00
...
3522 2020-04-14 00:00:00
3523 2020-04-15 00:00:00
3524 2020-04-16 00:00:00
3525 2020-04-17 00:00:00
3526 2020-04-20 00:00:00
Name: tDate, Length: 3527, dtype: object
print(T)
0 2004-09-15
1 2004-10-20
2 2004-11-17
3 2004-12-22
4 2005-01-19
...
203 2021-08-18
204 2021-09-15
205 2021-10-20
206 2021-11-17
207 2021-12-22
Name: tDate, Length: 208, dtype: datetime64[ns]
I would like to get a mat = np.array(len(t),len(T))
containing the difference in days between each element of t and all elements of T.
I tried np.array([_ - t for _ in T])
but this prints the Timestamps as int
, while I need them as number of days between the two dates (also int
tho). I also prefer to do it somehow in numpy
so that it is faster.
np.array([_ - t for _ in T])
array([[ -50025600000000000, -50112000000000000, -50198400000000000,
..., -491788800000000000, -491875200000000000,
-492134400000000000],
[ -47001600000000000, -47088000000000000, -47174400000000000,
..., -488764800000000000, -488851200000000000,
-489110400000000000],
[ -44582400000000000, -44668800000000000, -44755200000000000,
..., -486345600000000000, -486432000000000000,
-486691200000000000],
...,
[ 489456000000000000, 489369600000000000, 489283200000000000,
..., 47692800000000000, 47606400000000000,
47347200000000000],
[ 491875200000000000, 491788800000000000, 491702400000000000,
..., 50112000000000000, 50025600000000000,
49766400000000000],
[ 494899200000000000, 494812800000000000, 494726400000000000,
..., 53136000000000000, 53049600000000000,
52790400000000000]], dtype='timedelta64[ns]')