for n in range(len(A)):
    for _ in range(A[n]):
        choices.append(n)
vals = numpy.random.choice(choices, N, False)
B = numpy.zeros(len(A), dtype=int)
for index in range(N):
    B[vals[index]] += 1
return B
Down-sampling with numpy