[SciPy-user] Finding Gaps in an Array

Lorenzo Isella lorenzo.isella at gmail.com
Mon Jul 6 04:18:07 EDT 2009


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



More information about the SciPy-User mailing list