- 导入鸢尾属植物数据集,保持文本不变
import numpy as np
iris_type = np.dtype({
"names":["sepallength","sepalwidth","petallength","petalwidth","species"],
"formats":["f8","f8","f8","f8","U30"]})
iris_data = np.loadtxt("iris.csv", dtype=iris_type,delimiter=',',skiprows=1)
- 求出鸢尾属植物萼片长度的平均值、中位数和标准差(第1列,sepallength)
print("鸢尾属植物萼片长度的平均值为",round(np.mean(iris_data["sepallength"]),3),"cm")
print("鸢尾属植物萼片长度的中位数为",round(np.median(iris_data["sepallength"]),3),"cm")
print("鸢尾属植物萼片长度的标准差为",round(np.std(iris_data["sepallength"]),3))
鸢尾属植物萼片长度的平均值为 5.843 cm
鸢尾属植物萼片长度的中位数为 5.8 cm
鸢尾属植物萼片长度的标准差为 0.825
- 创建一种标准化形式的鸢尾属植物萼片长度,其值正好介于0和1之间,这样最小值为0,最大值为1(第1列,sepallength)
np.set_printoptions(threshold=20)
(iris_data["sepallength"]-np.mean(iris_data["sepallength"]))/np.std(iris_data["sepallength"])
array([-0.90068117, -1.14301691, -1.38535265, ..., 0.79566902,
0.4321654 , 0.06866179])
- 找到鸢尾属植物萼片长度的第5和第95百分位数(第1列,sepallength)
np.quantile(iris_data["sepallength"],[