I have a numpy array:
a = [3., 0., 4., 2., 0., 0., 0.]
I would like a new array, created from this, where the non zero elements are converted to their value in zeros and zero elements are converted to a single number equal to the number of consecutive zeros i.e:
b = [0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 3.]
Looking for a vectorized way to do this as the array will have > 1 million elements. Any help much appreciated.