I have two 1D Numpy arrays index_data and charge, which are the same length and contain ints and floats respectively. I am trying to make a total_charge array as follows:
total_charge = []
for i in range(len(index_data)):
if index_data[i] == 0:
total_charge.append(charge[i])
else:
total_charge[-1] += charge[i]
total_charge = np.array(total_charge)
How would I vectorize this? Help me Numpy wizards, you're my only hope.