Numpy:创建随机字符串并制作统一(Numpy: create random strings and make uniform)

编程入门 行业动态 更新时间:2024-10-24 10:20:12
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))

更多推荐

本文发布于:2023-07-16 22:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1135408.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   create   Numpy   uniform   strings

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!