[Numpy-discussion] List/location of consecutive integers
David Warde-Farley
dwf at cs.toronto.edu
Fri May 22 15:59:48 EDT 2009
On 22-May-09, at 1:03 PM, Christopher Barker wrote:
> In [104]: zip(indices[np.r_[True, breaks[:-1]]], indices[breaks])
I don't think this is very general:
In [53]: indices
Out[53]:
array([ -3, 1, 2, 3, 4, 5, 6, 7, 8,
9, 255, 256, 257, 258, 10001, 10002, 10003, 10004])
In [54]: breaks = diff(indices) != 1
In [55]: zip(indices[np.r_[True, breaks[:-1]]], indices[breaks])
Out[55]: [(-3, -3), (1, 9), (255, 258)]
More information about the NumPy-Discussion
mailing list