def manual(arr):
    out = []
count = 0
for x in arr:
    if x == 1:
        count += 1
if x == 0:
    count = 0
out.append(count)
return out

def test():
    for w in [1, 2, 10, 10 ** 4]:
        for trial in range(100):
            for vals in ([0, 1], [0, 1, 2]):
                b = np.random.choice(vals, size=w)
assert (rcount(b) == manual(b)).all()
print('hooray!')
Совокупное количество в NumPy без итерации