I'm not sure if this is possible but here goes. Suppose I have an array:
array1 = [0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]
and now I would like to create a numpy 1D array consisting of 5 elements that are randomly drawn from array1 AND with the condition that the sum is equal to 1. Example is something like, a numpy array that looks like [.2,.2,.2,.1,.1].
currently I use the random module, and choice function that looks like this:
range1= np.array([choice(array1),choice(array1),choice(array1),choice(array1),choice(array1)])then checking range1 to see if it meets the criteria; I'm wondering if there is faster way , something similar torandomArray = np.random.random()instead.Would be even better if I can store this array in some library so that if I try to generate 100 of such array, that there is no repeat but this is not necessary.
[0, .1, .2, .3, .4], which should add up close to1(floating point rounding may cause problems if you're not careful). If duplicates are allowed, then there's more than one option and the problem isn't trivial.