I need to populate a numpy array, execution speed is important to me. The array will use a dictionary which will specify how many instances (indexed key value) of the array value (key value) I need.
The script below is my attempt, testing shows it takes 0.14 seconds to run but if I remove the hstack it runs in 0.004 s. So I conclude that it is the concatenating of the array that is taking the time. What's a better method?
Note the dictionary below is just a test case, in general I will have about a 100 different values and each value will repeat approximately 10,000 times.
td = {}
for ii in range(100):
td[ii] = 10000+ii
a = np.ones(0)
for aa in td:
a = np.hstack((a,np.ones(td[aa])*aa))