# [SciPy-User] Matching date lists

Keith Goodman kwgoodman@gmail....
Thu Feb 4 10:47:04 CST 2010

```On Thu, Feb 4, 2010 at 8:31 AM, Lionel Roubeyrie
<lroubeyrie@limair.asso.fr> wrote:
> Hi,
> a possible way is to use KDTree by converting datetimes to seconds from the epoch :
> ######################################
> import datetime
> import time
> from scipy.spatial import KDTree
>
> [~]|87> a
>    <87>
> [datetime.datetime(2009, 12, 23, 13, 57, 16),
>  datetime.datetime(2009, 12, 23, 13, 58, 15),
>  datetime.datetime(2009, 12, 23, 13, 59, 14),
>  datetime.datetime(2009, 12, 23, 14, 0, 14),
>  datetime.datetime(2009, 12, 23, 14, 1, 13),
>  datetime.datetime(2009, 12, 23, 14, 2, 13),
>  datetime.datetime(2009, 12, 23, 14, 3, 13),
>  datetime.datetime(2009, 12, 23, 14, 4, 12),
>  datetime.datetime(2009, 12, 23, 14, 5, 12),
>  datetime.datetime(2009, 12, 23, 14, 6, 12)]
> [~]|88> b
>    <88>
> [datetime.datetime(2009, 12, 23, 13, 57, 21),
>  datetime.datetime(2009, 12, 23, 13, 57, 28),
>  datetime.datetime(2009, 12, 23, 13, 57, 37),
>  datetime.datetime(2009, 12, 23, 13, 57, 44),
>  datetime.datetime(2009, 12, 23, 13, 57, 53),
>  datetime.datetime(2009, 12, 23, 13, 58, 2),
>  datetime.datetime(2009, 12, 23, 13, 58, 9),
>  datetime.datetime(2009, 12, 23, 13, 58, 17),
>  datetime.datetime(2009, 12, 23, 13, 58, 25),
>  datetime.datetime(2009, 12, 23, 13, 58, 33)]
> [~]|89> asec=[time.mktime(i.timetuple()) for i in a]
> [~]|90> bsec=[time.mktime(i.timetuple()) for i in b]
> [~]|91> atree=KDTree(zip(asec, zeros(len(asec))))
> [~]|92> btree=KDTree(zip(bsec, zeros(len(bsec))))
> [~]|93> atree.query(btree.data[0] )[1]
>    <93> 0
> [~]|94> atree.query(btree.data[7] )[1]
>    <94> 1
> ######################################
>
> Yes, you can join space and time \o/

I thought of that too. But I noticed that KDTree doesn't like 1d
arrays. It crashes here:

--> 127         self.n, self.m = np.shape(self.data)

Would an np.atleast_2d() fix that?
```