[Numpy-discussion] Overlapping time series
Sturla Molden
sturla.molden at gmail.com
Tue Feb 11 09:38:23 EST 2014
Daniele Nicolodi <daniele at grinta.net> wrote:
> I was probably not that clear: I have two 2xN arrays, one for each data
> recording, one column for time (taken from the same clock for both
> measurements) and one with data values. Each array has some gaps.
If you want all subarrays where both timeseries are sampled, a single loop
through the data
can fix that. First find the smallest common timestamp. This is the first
starting point. Then loop and follow the timestamps. As long as they are in
synch, do just continue. If one timeseries suddenly skips forward (i.e.
there is a gap), you have an end point. Then slice between the start and
the end point, and append the view array to a list. Follow the timeseries
that did not skip until timestamps are synchronous again, and you have the
next starting point. Then just continue like this until the the two
timeseries are exhausted. It is an O(n) strategy, so it will not be
inefficient. If you are worried about the loop and performance, both Numba
and Cython can transform this into C speed. Numba takes less effort to use.
But Python loops are actually much faster than most scientists used to
Matlab and the like would expect.
Sturla
More information about the NumPy-Discussion
mailing list