mercredi 11 décembre 2019

How to generate random numbers based on a 3d weighted array in R?

I have a 3d arrayand each dimension contains 7 elements(Overall 7*7*7= 343 elements). Each element contains a number between 0 and 1 which is the weight of that cell:

pop = sample(1 : 100, 7 ** 3, replace = TRUE)
prob = array(pop / sum(pop), c(7,7,7))

Now, I need to randomly select one cell of this array based on the weight of each elements.

But, i don't know how to select a cell randomly. I wish the proper response returns 3 different numbers between 1 to 7.

For example, if it returns 2,4,3 then i figure out it is the cell with coordination of 2,4,3




Aucun commentaire:

Enregistrer un commentaire