import numpy as np import matplotlib.pyplot as plt mu = 1 #期望为1 sigma = 3 #标准差为3 num = 10000 #个数为10000 rand_data = np.random.normal(mu, sigma, num) print(rand_data.shape,type(rand_data)) count, bins, ignored = plt.hist(rand_data, 30, normed=True) plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *np.exp( - (bins - mu)**2 / (2 * sigma**2)), linewidth=2, color='r') plt.show() np.arange(5) list(range(5)) np.array([a,b]) np.arange(0,60,5) .reshape(3,4) np.linspace(0,20) #在指定的间隔内返回均匀间隔的数字。 np.random.random(10) #(0,1)以内10个随机浮点数 np.random.randint(1,100,[5,5]) #(1,100)以内的5行5列随机整数 np.random.rand(2,3) #产生2行3列均匀分布随机数组 np.random.randn(3,3) #3行3列正态分布随机数据 import numpy from sklearn.datasets import load_iris data = load_iris() print(data) petal_length = data['data'][,3] data1 = np.max(petal_length) data2 = np.min(petal_length) data3 = np.meanpetal_length) data4 = np.std(petal_length) data5 = np.median(petal_length