I'm new to programming, I have a numpy array as (the first column is the indices)
rows = np.array([5,6,7,8,14,15,16,31])
0 5
1 6
2 7
3 8
4 14
5 15
6 16
7 31
I need to get starting and ending indices of sub-arrays of consecutive integers, such as 0 and 3, 4 and 6 etc. I tried to do it like this
start = np.array([])
end = np.array([])
c = 0
while c < len(rows):
for i in range(c, len(rows)):
if rows[i]-rows[i+1] > 1:
np.append(start, c)
np.append(end, i)
c = i+1
It doesn't work, any suggestions?