numpy 中的randn()函数介绍

时间:2024-03-11 08:01:07
>>> np.random.randn()
2.1923875335537315 #random
生成正态分布矩阵:

For random samples from N(\mu, \sigma^2), use:

sigma np.random.randn(...) mu

 2.5 * np.random.randn(2, 4) + 3 #生成2行4列的符合(3,2.5^2)正态分布矩阵 其中u=3 σ=2.5
array([[-4.49401501,  4.00950034, -1.81814867,  7.29718677],  #random
       [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]]) #random
randn(30)生成6*5矩阵 N~(0,1)
randn(50)生成10*5矩阵

 matplotlib中注解函数

# annotate参数说明:xy = (2, 1) :所要标注的位置坐标
# xytext:标注文本所在位置
# arrowprops:标注箭头属性信息(它的内用可以自己试验一下)
# ‘local max\':标注文本,可以随意替换
annotate(r\'$\cos(\frac{2\pi}{3})=-\frac{1}{2}$\', xy=(t, np.cos(t)), xycoords=\'data\', xytext=(-90, -50), textcoords=\'offset points\', fontsize=16, arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2"))

matplotlib中画点函数解析

t = 2 * np.pi / 3
#第一个参数点的横坐标集合
#第二个参数点的纵坐标集合
#第三个参数该点的半径大小
#第四个参数该点的颜色
scatter([t, t], [np.cos(t), np.sin(t)], 20, color=\'red\')

 

# 该函数意义为从(t,0)-(t,np.sin(t))画虚线
# 第一个参数为所有点的x坐标集合
# 第二个参数为所有点的y坐标集合
plot([t, t], [0, np.sin(t)], color=\'red\', linewidth=2.5, linestyle="--")