矩阵- Matrices 线性代数

(19) 2024-05-09 22:01:02

矩阵
在数学中,矩阵(Matrix)是一个按照长方阵列排列的复数或实数集合

矩阵- Matrices 线性代数 (https://mushiming.com/)  第1张
矩阵- Matrices 线性代数 (https://mushiming.com/)  第2张

矩阵相加
通常的矩阵加法被定义在两个相同大小的矩阵

矩阵- Matrices 线性代数 (https://mushiming.com/)  第3张

矩阵乘法

矩阵和向量的乘法
如图:m×n 的矩阵乘以 n×1 的向量,得到的是 m×1 的向量
矩阵- Matrices 线性代数 (https://mushiming.com/)  第4张

矩阵乘法:
m×n 矩阵乘以 n×o 矩阵,变成 m×o 矩阵。
矩阵- Matrices 线性代数 (https://mushiming.com/)  第5张

矩阵乘法的性质:
矩阵的乘法不满足交换律:A×B≠B×A
矩阵的乘法满足结合律。即:A×(B×C)=(A×B)×C
单位矩阵:在矩阵的乘法中,有一种矩阵起着特殊的作用,如同数的乘法中的 1,我们称
这种矩阵为单位矩阵.它是个方阵,一般用 I 或者 E 表示,本讲义都用 I 代表单位矩阵,从左上角到右下角的对角线(称为主对角线)上的元素均为 1 以外全都为 0。如:
对于单位矩阵,有 AI=IA=A
矩阵- Matrices 线性代数 (https://mushiming.com/)  第6张

矩阵的逆
如矩阵 A 是一个 m×m 矩阵(方阵),如果有逆矩阵,则: AA1=A1A=I
矩阵- Matrices 线性代数 (https://mushiming.com/)  第7张

矩阵倒Code置
设 A 为 m×n 阶矩阵(即 m 行 n 列),第 i 行 j 列的元素是 a(i,j),即:A=a(i,j)
矩阵- Matrices 线性代数 (https://mushiming.com/)  第8张

Python Code

dot()
同线性代数中矩阵乘法的定义
np.dot(A, B):对于二维矩阵,计算真正意义上的矩阵乘积,同线性代数中矩阵乘法的定义。对于一维矩阵,计算两者的内积。

code

import numpy as np

# 2-D array: 2 x 3
two_dim_matrix_one = np.array([[1, 2, 3], [4, 5, 6]])
# 2-D array: 3 x 2
two_dim_matrix_two = np.array([[1, 2], [3, 4], [5, 6]])

two_multi_res = np.dot(two_dim_matrix_one, two_dim_matrix_two)
print('two_multi_res: %s' %(two_multi_res))

# 1-D array
one_dim_vec_one = np.array([1, 2, 3])
one_dim_vec_two = np.array([4, 5, 6])
one_result_res = np.dot(one_dim_vec_one, one_dim_vec_two)
print('one_result_res: %s' %(one_result_res))

未完…


参考:

斯坦福大学 2014 机器学习教程


THE END

发表回复