mardi 30 juillet 2019

Is there a way to manipulate the shuffle function?

I am shuffling an array of, say, 8760 numbers sorted by their respective values (from low to high) to generate a quasi-stochastic time series. However, I want higher values to have a higher chance of appearing within the first quarter and last of the resulting array and lower values within the second and third half. My questions are:

  1. Is there a way to manipulate the shuffle function so it works with custom probabilities or do I have to "do it myself" afterwards?
  2. Is there some other package I do not know yet which can do this?
  3. Am I possibly blind and overlooking another much easier way to do this?
a = np.array([0, 0, 0, 0, 0, ...
              1, 1, 1, ...
              ...
              14, 14, 14, 14, 14, 14])

a_shuff = random.shuffle(a)

# desired resultwould be something like 
a_shuff = [14, 14, 8, 12, ... 0, 4, 2, 6, 3, ... 13, 14, 9, 11, 12]

It may be important to note that each value has a different number of occurances within the array.

I hope that describes my problem well enough - I am new to both Python and Stackoverflow. I'm happy to answer any further questions on this matter.




Aucun commentaire:

Enregistrer un commentaire