博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
10.18作业
阅读量:7092 次
发布时间:2019-06-28

本文共 1549 字,大约阅读时间需要 5 分钟。

 计算鸢尾花花瓣长度的最大值,平均值,中值,均方差。

import numpy as npfrom sklearn.datasets import load_iris    data = load_iris()petal_length = data['data'][:,2]#鸢尾花花瓣的长度值print(petal_length)data1 = np.max(petal_length)    #鸢尾花花瓣的长度最大值data2 = np.min(petal_length)     #最小值data3 = np.mean(petal_length)     #均值data4 = np.std(petal_length)      #标准差(均方值)data5 = np.median(petal_length)     #中位数print('最大值:',data1,'最小值:',data2,'均值:',data3,'均方值:',data4,'中位数:',data5)

print(np.random.normal(1,5,30)) # 用np.random.normal()产生一个正态分布的随机数组,并显示出来print(np.random.randn(5,5))   # np.random.randn()产生一个正态分布的随机数组,并显示出来

#显示鸢尾花花瓣长度的正态分布图import numpy as npimport matplotlib.pyplot as pltmu = np.mean(petal_length)  # 期望值sigma = np.std(petal_length)  # 标准差num = 10000  #个数为10000rand_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()

# 显示鸢尾花花瓣长度的曲线图plt.plot(np.linspace(0,150,num=150),petal_length,'r')plt.show()

# 显示鸢尾花花瓣长度的散点图plt.scatter(np.linspace(0,160,num=150),petal_length,alpha=1,marker='x',color='green')plt.show()

 

print(np.arange(5))  #list(range(5))print(np.array([3,8]))print(np.arange(0,50,5))print(np.linspace(0,30)) #在指定的间隔内返回均匀间隔的数字。print(np.random.random(10)) #(0,1)以内10个随机浮点数print(np.random.randint(1,100,[5,5])) #(1,100)以内的5行5列随机整数print(np.random.rand(2,3)) #产生2行3列均匀分布随机数组print(np.random.randn(3,3)) #3行3列正态分布随机数据

 

转载于:https://www.cnblogs.com/Tlzlykc/p/9822521.html

你可能感兴趣的文章
error:Flash Download failed-“Cortex-M3”,“Programming Algorithm”【转】
查看>>
【转】spring boot web相关配置
查看>>
oc53--autorelease注意事项
查看>>
sigmod2017.org
查看>>
MongoDB集群运维笔记
查看>>
Python代码优化及技巧笔记(一)
查看>>
Caused by: java.lang.NoClassDefFoundError: org/apache/neethi/AssertionBuilderFactory
查看>>
Ocelot 集成Butterfly 实现分布式跟踪
查看>>
(转)各种语言写网络爬虫有什么优点缺点
查看>>
好用的端口监控软件:Port Explorer
查看>>
Cisco无线控制器配置Radius
查看>>
iota 币产生私钥的方法
查看>>
Mysql数据类型DECIMAL(M,D)用法
查看>>
006-Shell printf 命令
查看>>
leetcode 39. Combination Sum 40. Combination Sum II
查看>>
python测试开发django-4.获取url参数和name的作用
查看>>
C# IEnumerable和IEnumerator的区别,如何实现
查看>>
android adb命令行工具使用
查看>>
[转]聊聊.net程序设计——浅谈使用VS2010建模拓展
查看>>
Central Europe Regional Contest 2011
查看>>