Numpy:创建随机字符串并制作统一(Numpy: create random strings and make uniform)
我试过以下代码:
import numpy as np let = ['A', 'B', 'C', 'D'] print(np.random.choice(let, 8, p=[0.25, 0.25, 0.25, 0.25]))输出:
['A' 'B' 'C' 'A' 'A' 'C' 'A' 'A']它应该是随机的,但我想要以下输出:25%A,25%,B,25%C,25%D。如下所示:
['A' 'B' 'C' 'A' 'C' 'D' 'D' 'B']我错过了什么?
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?
最满意答案
Per RedEyed评论:
import numpy as np let = ['A', 'B', 'C', 'D'] print(np.random.permutation(let*4))Per RedEyed comment:
import numpy as np let = ['A', 'B', 'C', 'D'] print(np.random.permutation(let*4))更多推荐
发布评论