I have a vector of fractions a = [0.04352034965262487, 0.480655360084497, 0.02655889003246612, 0.449265400230412, 0.0]
of type float64
such that of course sum(a)=1
. These fractions represent persentages of some number K=128
. So, multiplying a
by K
we obtain the number of elements in each fraction a*K =[5.570604755535983, 61.523886090815616, 3.3995379241556636, 57.50597122949274, 0.0]
.
I want to transform this vector a*K
into an int
vector and respect the sum of elements of a*K
to be K
. What I am doing is floor
but this will give 126
and not 128
. When I do round
I obtain 129
and when I do ceil
I obtain 130
.
I thought of applying ceil
and then remove randomly the 2 elements that exceeds 128
. Is there a better way?