#计算鸢尾花的花瓣长度的最大值,平均值,中值,均方差
import numpy as np
from sklearn.datasets import load_iris
data=load_iris()
petal_length = data.data[:,2]
print(petal_length)
print("最大值",np.max(petal_length))
print("平均值",np.mean(petal_length))
print("中位数",np.median(petal_length))
print("标准差",np.std(petal_length))
![](https://img2018.cnblogs.com/blog/1482909/201810/1482909-20181022153637696-515970801.png)
#用np.random.normal()产生一个正态分布的随机数组,并显示出来
np.random.normal(2,4,100)
mu=2
sigma=4
num=100
m_data=np.random.normal(mu,sigma,num)
print(m_data)
![](https://img2018.cnblogs.com/blog/1482909/201810/1482909-20181022153820969-1776239444.png)
mport matplotlib.pyplot as plt
mu=np.mean(petal_length)
sigma=np.std(petal_length)
num=150
rand_data=np.random.normal(mu,sigma,num)
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()
![](https://img2018.cnblogs.com/blog/1482909/201810/1482909-20181022153904608-1972387849.png)
# 显示鸢尾花花瓣长度的曲线图
plt.plot(np.linspace(1,160,num=150),pental_len,'g')
plt.show()
# 显示鸢尾花花瓣长度的散点图
plt.scatter(np.linspace(1,160,num=150),petal_length,alpha=1,marker='x')
plt.show()
![](https://img2018.cnblogs.com/blog/1482909/201810/1482909-20181022154549556-1330914852.png)
# 显示鸢尾花花瓣长度的曲线图
plt.plot(np.linspace(1,160,num=150),petal_length,'g')
plt.show()
![](https://img2018.cnblogs.com/blog/1482909/201810/1482909-20181022154624161-886376398.png)