numpy 生成满足正态分布的随机数
numpy随机采样;
numpy直方图;
normal
def getData3():
r"""
生成正太分布的随机数;
:return:
"""
# data = np.random.uniform(0, 1, size = 1000)#随机均匀采样
# data3 = np.random.rand(1000) #随机均匀分布
#
# data2 = np.random.normal(0, 1, size = 1000)#正太分布,均值为0,方差为1
# data4 = np.random.randn(1000)#正太分布,均值为0,方差为1
point1 = (0.5, 0.5)
point2 = (2.5, 2.5)
a = np.random.normal(point1[0], 1, size = (1000,1))
b = np.random.normal(point1[1], 1, size = (1000,1))
c = np.random.normal(point2[0], 1, size = (1000,1))
d = np.random.normal(point2[1], 1, size = (1000,1))
G1 = pd.DataFrame(data = np.concatenate((a,b),axis=1), columns=['X','Y'])
G2 = pd.DataFrame(data = np.concatenate((c,d),axis=1), columns=['X','Y'])
return (G1.values.T, G2.values.T)
并将其可视化出来
fig, ax = plt.subplots()
# 绘制散点图;
G1, G2 = getData3()
ax.scatter(G1[0,:], G1[1,:])
ax.scatter(G2[0,:], G2[1,:])
#绘制直方图;
# ax.hist(data,bins=20) #随机均匀采样
# ax.hist(data3,bins=20) #随机均匀分布
# ax.hist(data2,bins=20) #正太分布,均值为0,方差为1
# ax.hist(data4,bins=20) #正太分布,均值为0,方差为1
#固定X轴、Y轴的范围
# ax.set_ylim(ymin = 0, ymax = 130)
# ax.set_xlim(xmin = -5, xmax = 5)
fig.show()