# [SciPy-user] Finding Gaps in an Array

Mon Jul 6 07:01:14 CDT 2009

```Hi Lorenzo,

numpy.diff(your_array)

will give you the times between entries,

numpy.where(numpy.diff(your_array) > 20)

will give the indices where the gap was longer than 20

cheers,
David

----- Original Message ----
From: Lorenzo Isella <lorenzo.isella@gmail.com>
To: scipy-user@scipy.org
Sent: Monday, 6 July, 2009 8:18:07 PM
Subject: [SciPy-user] Finding Gaps in an Array

Dear All,
Suppose you have an integer array whose entries are like the one below
(no entry is ever repeated and the array is sorted in increasing order)

1240070020
1240070040
1240070060
1240070080
1240070100
1240070180
1240070200
1240070620
1240070640
1240070880
1240070900
1240070940
1240070980
1240071000
1240071020
1240071040
1240071060
1240071080
1240071100
1240071120
1240071140
1240071160
1240071180
1240071200
1240071220
1240071240
1240071260
1240071280
1240071300

Let us assume that the entries represent contact times (in seconds)
between 2 objects (one does not need to know anything else for this
post). The value of the initial time does not matter (i.e. you could
subtract it to all the elements in the array to have a list starting
from zero). Now, you define the contact duration as the time spanned by
consecutive entries evenly spaced by 20 seconds.
E.g. in the array above, the first 5 elements define a contact of
duration 1240070100-1240070020=80. Then there is an 80-sec gap
(1240070180-1240070100) followed by a contact of duration 20
(1240070200-1240070180).
How can you automatically calculate these intervals?
Any suggestion is welcome.
Cheers

Lorenzo
_______________________________________________
SciPy-user mailing list
SciPy-user@scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user

```