0

I have tried the following code:

import numpy as np
let = ['A', 'B', 'C', 'D']
print(np.random.choice(let, 8, p=[0.25, 0.25, 0.25, 0.25]))

output:

['A' 'B' 'C' 'A' 'A' 'C' 'A' 'A']

It should be random but I want the following output: 25% A, 25%, B, 25% C, 25% D. Something like the following:

['A' 'B' 'C' 'A' 'C' 'D' 'D' 'B']

What am I missing?

8
  • So, the number of elements in output would be double of input? Commented Sep 16, 2017 at 20:38
  • The number of elements of output could by any length. I just choose 8 as an example. But the actually number could be any. For instance, 100 A's, 100 B's, 100 C's, 100 D's would also work. I just want each element to be 25% of total Commented Sep 16, 2017 at 20:43
  • You want random permutations of eight A's, eight B's, eight C's and eight D's. Correct? Commented Sep 16, 2017 at 20:48
  • And the weights would always be uniformly distributed? Commented Sep 16, 2017 at 20:58
  • With permutations: np.random.permutation(let*4) Commented Sep 16, 2017 at 20:58

1 Answer 1

1

Per RedEyed comment:

import numpy as np
let = ['A', 'B', 'C', 'D']
print(np.random.permutation(let*4))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.