a=[1,2,3,4,5,6,7,8,9,10]
print(a)
import numpy as np
m=np.arange(24)
print(m)
#n=m.reshape(3,8)
#print(n)
#m.shape=(2,3,1,4)
#print(m)
#m.resize(3,8)
#print(m)
#m.ravel()
#print(m)
#n.flatten()
#print(n)
#a=np.random.random(10)#随机产生10个浮点数
#print(a)
#a=np.random.randint(1,100,[5,5])#1到100以内的5行5个的随机整数
#print(a)
#a=np.random.rand(2,3)#产生两行3列的均匀分布的随机数组
#print(a)
#a=np.random.randn(3,3) 产生3行3列的正态分布随机数组
#print(a)
b=np.max(a)#最大值
print(b)
b=np.min(a)#最小值
print(b)
b=np.mean(a)#求均值
print(b)
b=np.std(a)#求标准差
print(b)
b=np.median(a)#返回数组的中位数
# print(b)
#安装scipy,numpy,sklearn包
import numpy as np
import scipy
import sklearn
from sklearn.datasets import load_iris#从sklearn包自带的数据集中读出鸢尾花数据集data
data = load_iris()
print('数据类型:',type(data))#查看data类型,包含哪些数据
print('数据内容:',data.keys())
iris_feature = data['feature_names'],data['data']#取出鸢尾花特征和鸢尾花类别数据,查看其形状及数据类型
print('鸢尾花数据:',iris_feature)
iris_target = data.target,data.target_names
print('鸢尾花形状类别:',iris_target)
sepal_length = numpy.array(list(len[0] for len in data['data']))#取出所有花的花萼长度(cm)的数据
print('所有花萼长度:',sepal_length)
petal_length = numpy.array(list(len[2] for len in data['data']))#取出所有花的花瓣长度(cm)+花瓣宽度(cm)的数据
petal_length.resize(5,30)
petal_width = numpy.array(list(len[3] for len in data['data']))
petal_width.resize(5,30)
iris_lens = (petal_length,petal_width)
print('所有花瓣长宽:',iris_lens)
#取出某朵花的四个特征及其类别
print('特征:',data['data'][0])
print('类别:',data['target'][0])
#将所有花的特征和类别分成三组,每组50个,建立每种花的相应列表,存放数据
iris_setosa = []
iris_versicolor = []
iris_virginica = []
# 用for循环分类,根据观察可知当target为0时对应setosa类型,1为versicolor,2为virginica
for i in range(0,150):
if data['target'][i] == 0: # 类别为0的即为setosa,生成一条0为setosa类的鸢尾花花数据
data1 = data['data'][i].tolist()
data1.append('setosa')
iris_setosa.append(data1)
elif data['target'][i] == 1: # 类别为1的即为versicolor,生成一条1为versicolor类的鸢尾花数据
data1 = data['data'][i].tolist()
data1.append('versicolor')
iris_versicolor.append(data1)
else: #剩下类别为2的归为virginica
data1 = data['data'][i].tolist()
data1.append('virginica')
iris_virginica.append(data1)
#生成新的数组,每个元素包含四个特征+类别
datas = (iris_setosa,iris_versicolor,iris_virginica)
print('新数组分类结果:',datas)