$ irb -rnarray
irb> a = NArray[0,1,2,0,0,5,0,7,8,9]
irb> tmp = NArray.new( a.typecode, a.size+2 )
irb> tmp[1..-2] = a
irb> tmp
=> NArray.int(12):
[ 0, 0, 1, 2, 0, 0, 5, 0, 7, 8, 9, 0 ]
irb> empty = tmp.eq(0)
=> NArray.byte(12):
[ 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1 ]
irb> beg = (~empty[1..-1] & empty[0..-2]).where
=> NArray.int(3):
[ 1, 5, 7 ]
irb> fin = (empty[1..-1] & ~empty[0..-2]).where
=> NArray.int(3):
[ 3, 6, 10 ]
irb> range = NArray[beg,fin].transpose(1,0)
=> NArray.int(2,3):
[ [ 1, 3 ],
[ 5, 6 ],
[ 7, 10 ] ]