a
m = a != 0
(m[1:] > m[:-1]).sum() + m[0]
a[0] = 7
m = a != 0
(m[1:] > m[:-1]).sum() + m[0]
a[-2:] = [0, 4]
m = a != 0
(m[1:] > m[:-1]).sum() + m[0]
Count number of clusters of non-zero values in Python?