I have an array a of values whose values at each index idx I'd like to repeat a certain amount b[idx] of times, given at the same index idx in another array (b), like such:
a = numpy.array([1, 2, 3 ,4, 5])
b = numpy.array([2, 3, 1, 2, 4])
Desired output:
c = numpy.array([1, 1, 2, 2, 2, 3, 4, 4, 5, 5, 5, 5])
I realize I could do something like this:
len_a = numpy.shape(a)[0]
sum_b = sum(b)
c = numpy.zeros((1, 0))
for idx in range(len_a):
repeated_a = numpy.repeat(a[idx], b[idx])
repeated_a = numpy.reshape(repeated_a, (1, numpy.shape(repeated_a)[0]))
c = numpy.hstack((c, repeated_a))
However, looping is not a good option because it is slow. How would I go about making this faster? Some form of vectorization perhaps.