suppose I have a python list or a python 1-d array (represented in numpy). assume that there is a contiguous stretch of elements how can I find the start and end coordinates (i.e. indices) of the stretch of non-zeros in this list or array? for example,
a = [0, 0, 0, 0, 1, 2, 3, 4]
nonzero_coords(a) should return [4, 7]. for:
b = [1, 2, 3, 4, 0, 0]
nonzero_coords(b) should return [0, 2].
thanks.