>>> np.random.randn() 2.1923875335537315 #random
生成正態分布矩陣:
For random samples from , 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="--")