Python:在列表或矩阵中具有一定概率的随机0 1生成器

Python:在列表或矩阵中具有一定概率的随机0 1生成器,python,arrays,random,probability,Python,Arrays,Random,Probability,我需要把逗号放在0和1之间,这样我就可以制作数据的柱状图 这是我的分布,但有没有办法在数组[0,0,0,1,0]中放入这样的逗号,或者直接从中生成直方图 #20 is the number of columns that we will have for x in np.arange(0.05 , 1 , 0.2): t = np.array(np.random.rand( 20 ) < x , int) print (t) 你想用逗号连接你的元素,但是你必须先把它们转换

我需要把逗号放在0和1之间,这样我就可以制作数据的柱状图

这是我的分布,但有没有办法在数组[0,0,0,1,0]中放入这样的逗号,或者直接从中生成直方图

#20 is the number of columns that we will have
for x in np.arange(0.05 , 1 , 0.2):
    t = np.array(np.random.rand( 20 ) < x , int)
    print (t)

你想用逗号连接你的元素,但是你必须先把它们转换成str

我想出了以下代码

for x in np.arange(0.05 , 1 , 0.2):
    t = np.array(np.random.rand( 20 ) < x , int)
    joined = ",".join(map(str, t))
    print(f"[{joined}]")
np.arange(0.05,1,0.2)中x的
:
t=np.array(np.random.rand(20)
请解释逗号与直方图的关系,以及只有两个可能值(0和1)的直方图是什么样子。如果您编写了一些代码来打印一个在值之间使用逗号而不是空格的数组,那么这将如何使您更接近于绘制直方图?
for x in np.arange(0.05 , 1 , 0.2):
    t = np.array(np.random.rand( 20 ) < x , int)
    joined = ",".join(map(str, t))
    print(f"[{joined}]")