Skip to content

Commit c1824dd

Browse files
committed
矩阵 向量空间 微积分 让数学与编程结合 python数据科学
矩阵 向量空间 微积分 让数学与编程结合 python数据科学
1 parent 77f1d8e commit c1824dd

File tree

2 files changed

+199
-0
lines changed

2 files changed

+199
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import numpy as np
2+
from numpy.linalg import inv
3+
4+
#创建矩阵
5+
6+
#使用numpy第一种方式创建矩阵 使用matrix类
7+
#但是matrix类 不是numpy推荐的 应主要学习numpy的array类
8+
# 这里注意 参数的格式 [[1,2],[3,4],[5,6]]
9+
A = np.matrix([[1,2],[3,4],[5,6]])
10+
11+
print("矩阵类A:{0}".format(A))
12+
13+
C = np.matrix('1,2,7;3,4,8;5,6,9')
14+
print("矩阵类C:{0}".format(C))
15+
16+
17+
#第二种方式创建矩阵 这里 矩阵元素
18+
#注意参数的格式
19+
B = np.array(range(1,7)).reshape(3,2)
20+
print("矩阵B:{0}".format(B))
21+
22+
23+
#这里注意矩阵运算两个矩阵相乘的问题
24+
#第一 如果是matrix类创建的矩阵 矩阵相乘需要 按照线性代数矩阵相乘的原则进行
25+
#线性代数 矩阵相乘
26+
#第二 如果是array创建的矩阵 这里需要注意 两个矩阵相乘按照哈达玛乘积原则进行
27+
'''
28+
需要注意的是,两个矩阵的标准乘积不是指两个矩阵中对应元素的乘积。
29+
不过, 那样的矩阵操作确实是存在的,
30+
被称为元素对应乘积 (element-wise product)
31+
或者哈 达玛乘积 (Hadamard product),
32+
'''
33+
34+
D = B*B
35+
36+
print('矩阵的哈达玛乘积:{0}'.format(D))
37+
38+
39+
#在线性代数中一些特殊矩阵 单位矩阵 对角矩阵 上三角与 下三角矩阵
40+
41+
#生成特殊矩阵 3行两列的 零矩阵
42+
A = np.zeros((3,2))
43+
print('零矩阵:{0}'.format(A))
44+
#生成特殊矩阵 单位矩阵 3行3列
45+
B = np.identity(3)
46+
print('单位矩阵:{0}'.format(B))
47+
48+
#生成特殊矩阵 对角矩阵
49+
50+
C = np.diag([1,2,3])
51+
52+
print('对角矩阵:{0}'.format(C))
53+
54+
55+
#矩阵中向量的提取
56+
57+
m = np.array(range(1,10)).reshape(3,3)
58+
print('矩阵m:{0}'.format(m))
59+
#提取行向量
60+
61+
p = m[[0,2]]
62+
63+
print('提取矩阵的指定行的行向量:{0}'.format(p))
64+
65+
#方法2
66+
print('矩阵m:{0}'.format(m))
67+
p = m[[True,False,True]]
68+
69+
print('提取矩阵的指定行的行向量2:{0}'.format(p))
70+
71+
#提取列向量
72+
73+
l = m[:,[1,2]]
74+
75+
print('列向量:{0}'.format(l))
76+
77+
l = m[:,[False,True,True]]
78+
79+
print('列向量:{0}'.format(l))
80+
81+
82+
83+
#矩阵的运算 矩阵相加减 矩阵与数字的乘积
84+
85+
86+
n = np.array(range(1,5)).reshape(2,2)
87+
88+
print('矩阵n:{0}'.format(n))
89+
90+
91+
#矩阵的转置
92+
np.transpose(n)
93+
p = np.transpose(n)
94+
95+
print('矩阵n转置:{0}'.format(n))
96+
print('矩阵n转置结果:{0}'.format(p))
97+
98+
r = n + n
99+
100+
101+
print('矩阵加运算:{0}'.format(r))
102+
103+
r = n - n
104+
105+
print('矩阵减运算:{0}'.format(r))
106+
107+
#矩阵与数字的乘积
108+
109+
r = 3*n
110+
111+
print('矩阵与数字的乘积:{0}'.format(r))
112+
113+
114+
#矩阵的哈达玛乘积
115+
116+
p = n*n
117+
118+
print('矩阵的哈达玛乘积:{0}'.format(p))
119+
120+
#矩阵的线性代数乘法
121+
122+
p = n.dot(n)
123+
124+
print('矩阵的乘法:{0}'.format(p))
125+
126+
127+
#矩阵的逆矩阵
128+
129+
p = inv(n)
130+
131+
132+
print('矩阵的逆:{0}'.format(p))
133+
134+
135+
136+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'''
2+
向量空间
3+
4+
在数学上 任意一个三维行向量X = (x1,x2,x3)
5+
6+
都可以被写为X = x1(1,0,0) + x2(0,1,0) + x3(0,0,1)
7+
8+
这里有向量空间 三维空间的基的概念 同时也有向量的加法的概念
9+
10+
'''
11+
12+
'''
13+
在数学上 特征向量 与 特征值 并非只定义在 对称矩阵上
14+
事实上对任意一个方针M 满足下面的公式的向量和实数 分别为M的特征向量
15+
与特征值
16+
M(w)T = 𝛌(w)T
17+
18+
这里插入一个公式的记忆
19+
20+
关于逆矩阵 (k*A)的逆矩阵 等于 (1/k)*((A)的逆)
21+
22+
'''
23+
24+
'''
25+
导数和积分
26+
27+
在数据科学领域 积分被更多地用于理论研究 接触的机会少
28+
29+
但是导数被大量应用 主要用于工程实现(求解最优化问题)
30+
31+
速度函数曲线 V(t) = at; a是加速度 t为时间变量
32+
33+
位移函数曲线 S(t) = (1/2) * a * (t)²
34+
35+
这里 v 函数曲线积分 得到 位移函数曲线 S
36+
37+
位移函数曲线 S 求导得到 速度函数曲线 V
38+
39+
这里再引申 位移函数曲线 求 平均速度的公式
40+
41+
( l(t1) - l(t2) )/( t1 - t2 ) 得到平均速度
42+
43+
当我们求极限便得到某一时刻的瞬时速度
44+
45+
46+
而瞬时速度曲线 就是 V(t) 速度函数曲线
47+
48+
但是速度函数曲线表达式 却是 V = at, a为加速度 t为时间变量
49+
50+
51+
'''
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+

0 commit comments

Comments
 (0)