I'm fairly new to Python, and think this should be a fairly common problem, but can't find a solution. I've already looked at this page and found it helpful for one item, but I'm struggling to extend the example to multiple items without using a 'for' loop. I'm running this bit of code for 250 walkers through Emcee, so I'm looking for the fastest way possible.
I have a list of numbers, a = [x,y,z]
that I want to repeat b = [1,2,3]
times (for example), so I end up with a list of lists:
[
[x],
[y,y],
[z,z,z]
]
The 'for' loop I have is:
c = [ ]
for i in range (0,len(a)):
c.append([a[i]]*b[i])
Which does exactly what I want, but means my code is excruciatingly slow. I've also tried naively turning a and b into arrays and doing [a]*b
in the hopes that it would multiply element by element, but no joy.