摘要: import numpy as np from sklearn.datasets import load_iris iris=load_iris() x=iris.data[:,1] y=np.zeros(150) def initcent(x,k): #初始聚类中心数组 return x[0:k].reshape(k) def nearest(kc,i): #数组中的值,... 阅读全文
posted @ 2018-10-25 16:22 zhongwolin 阅读(1107) 评论(0) 推荐(0) 编辑
摘要: #计算鸢尾花花瓣长度的最大值,平均值,中值,均方差。 import numpy as np from sklearn.datasets import load_iris data=load_iris() iris=data.data petal_length=iris[:,2] #取所有行的第二列 print(np.mean(petal_length)) #平均值 print(np.... 阅读全文
posted @ 2018-10-18 22:01 zhongwolin 阅读(621) 评论(0) 推荐(0) 编辑
摘要: import numpy as np print(np.arange(5)) #长度为5的一维数组,虽然是[] print(list(range(5))) #此为列表 print(np.array([2,3])) #生成多为数组 print(np.linspace(0,20)) #在指定的间隔内返回均匀间隔的数字, # 生成了50个数,每个数的间隔一样,在0—20个数之间生成 print(n... 阅读全文
posted @ 2018-10-18 11:44 zhongwolin 阅读(90) 评论(0) 推荐(0) 编辑
摘要: #取出所有花的花瓣长度(cm)+花瓣宽度(cm)的数据len=numpy.array(list(len[1] for len in data['data']))len.resize(20,10)wid=numpy.array(list(wid[2] for wid in data['data'])) 阅读全文
posted @ 2018-10-15 19:28 zhongwolin 阅读(337) 评论(0) 推荐(0) 编辑
摘要: Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import numpy as np >>> a=list(range(10,1... 阅读全文
posted @ 2018-10-11 09:08 zhongwolin 阅读(724) 评论(0) 推荐(0) 编辑
摘要: a=list(range(10)) b=list(range(0,50,5)) c=[] for i in range(len(a)): c.append(a[i]**2+b[i]**3) print(a,b,c) def pySum(n): a=list(range(n)) b=list(range(0,5*n,5)) c=[] for ... 阅读全文
posted @ 2018-09-29 11:55 zhongwolin 阅读(121) 评论(0) 推荐(0) 编辑
摘要: #.英文小说 词频统计 #读取字符串 str fo=open('lines.txt','r',encoding='utf-8') lines=fo.read().lower() fo.close() print(lines) #字符串预处理 #全部转化为小写 h2=str.lower(lines) print(h2) #标准符号与特殊符号 sep = ',.;:?!-_' for en... 阅读全文
posted @ 2018-09-27 22:16 zhongwolin 阅读(614) 评论(0) 推荐(0) 编辑
摘要: 总结列表,元组,字典,集合的联系与区别。 列表 1.可以用list()函数或者方括号[]创建,元素之间用逗号’,‘’分隔。 2.列表的元素不需要具有相同的类型 3.使用索引来访问元素 元组 元组跟列表很像,只不过元组用小括号来实现() 具有以下特点: 1.可以用tuple()函数或者方括号()创建, 阅读全文
posted @ 2018-09-21 12:52 zhongwolin 阅读(330) 评论(0) 推荐(0) 编辑
摘要: #完成完整的温度转换程序 while True: a = int(input('摄氏转华氏请按1\n华氏转摄氏请按2:\n')) if a == 1: #用户输入摄氏度 celsius = float(input('输出摄氏温度:')) #计算华氏温度 fahrenheit = (celsius * 1.8)+32... 阅读全文
posted @ 2018-09-13 22:57 zhongwolin 阅读(284) 评论(0) 推荐(0) 编辑
摘要: name1 = input('请输入第一个名字:') name2 = input('请输入第二个名字:') name3 = input('请输入第三个名字:') print('\n{}买了一件新衣服,{}说这件衣服只适合肥婆穿,一会,他们敲响了{}的房门。\n\n'.format(name1,name2,name3)) #用户输入数字 num1=input('输入第一个数字:') ... 阅读全文
posted @ 2018-09-06 13:51 zhongwolin 阅读(177) 评论(0) 推荐(0) 编辑