Skip to content

Commit 0df1954

Browse files
committed
update numpy
1 parent 482e4e0 commit 0df1954

File tree

6 files changed

+89
-1
lines changed

6 files changed

+89
-1
lines changed

numpy&pandas/matplotlib.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sat May 19 15:39:56 2018
4+
5+
@author: Administrator
6+
"""
7+
# 将包导入到脚本中
8+
import numpy as np
9+
# pyplot() 是matplotlib库中最重要的函数
10+
from matplotlib import pyplot as plt
11+
12+
x = np.arange(1,11)
13+
y = 2 * x + 5
14+
15+
plt.title("matplotlib demo")
16+
plt.xlabel("x axis")
17+
plt.ylabel("y axis")
18+
plt.plot(x,y, "xb") # 函数绘制
19+
plt.show() # 图像显示
20+
21+
# 生成正弦波
22+
# 将包导入到脚本中
23+
import numpy as np
24+
# pyplot() 是matplotlib库中最重要的函数
25+
from matplotlib import pyplot as plt
26+
x = np.arange(0, 3 * np.pi, 0.1)
27+
y = np.sin(x)
28+
plt.title("sinx")
29+
plt.plot(x,y)
30+
plt.show()
31+
32+
# subplot 在一图中显示两部分
33+
import numpy as np
34+
import matplotlib.pyplot as plt
35+
# 计算正弦和余弦曲线上的点的 x 和 y 坐标
36+
x = np.arange(0, 3 * np.pi, 0.1)
37+
y_sin = np.sin(x)
38+
y_cos = np.cos(x)
39+
# 建立 subplot 网格,高为 2,宽为 1
40+
# 激活第一个 subplot
41+
plt.subplot(2, 1, 1)
42+
# 绘制第一个图像
43+
plt.plot(x, y_sin)
44+
plt.title('Sine')
45+
# 将第二个 subplot 激活,并绘制第二个图像
46+
plt.subplot(2, 1, 2)
47+
plt.plot(x, y_cos)
48+
plt.title('Cosine')
49+
# 展示图像
50+
plt.show()
51+
52+
# plt.bar() 显示柱状图
53+
from matplotlib import pyplot as plt
54+
x = [5,8,10]
55+
y = [12,16,6]
56+
x2 = [6,9,11]
57+
y2 = [6,15,7]
58+
plt.bar(x, y, align = 'center')
59+
plt.bar(x2, y2, color = 'g', align = 'center')
60+
plt.title('Bar graph')
61+
plt.ylabel('Y axis')
62+
plt.xlabel('X axis')
63+
plt.show()
64+
65+
# 小结
66+
# 1.引入matplotlib包 from matplotlib import pyplot as plt
67+
# 2. plt.plot(x,y) 绘制曲线图
68+
# 3. plt.bar(x,y) 绘制柱状图
69+
# 4. plt.title("xx")
70+
# 5. plt.xlabel("x axis")
71+
# 6. plt.show() 图像显示
File renamed without changes.
File renamed without changes.

numpy/numpy03.py renamed to numpy&pandas/numpy03.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@
3737
# np.vdot : 返回两个向量的点积
3838
print("向量点积:", np.vdot(a,b))
3939
# np.inner :返回一维数组的向量内积
40-
print("向量内积:", np.inner(np.array([1,2,3]), np.array([0,1,0])))
40+
print("向量内积:", np.inner(np.array([1,2,3]), np.array([0,1,0])))
41+
42+
# numpy.linalg.solve()函数给出矩阵形式线性方程组的解
43+
# numpy.linlg.inv() 计算矩阵的逆
File renamed without changes.

numpy/scikit-learn.py renamed to numpy&pandas/scikit-learn.py

+14
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@
2424
print(model.predict(data_x[:4,:]))
2525
print(data_y[:4])
2626

27+
# 使用KNN进行实例操作
28+
from sklearn import neighbors
29+
from sklearn import datasets
30+
# 加载数据
31+
iris = datasets.load_iris()
32+
print(iris)
33+
# 创建KNN模型
34+
knn = neighbors.KNeighborsClassifier()
35+
# fit
36+
knn.fit(iris.data, iris.target)
37+
# 预测
38+
predictedLabel = knn.predict([[0.1,0.2,0.3,0.4]])
39+
print(predictedLabel)
40+
#

0 commit comments

Comments
 (0)