给定正整数
m
m
m和
n
n
n和数域
P
P
P,
?
A
=
(
a
11
a
12
?
a
1
n
a
21
a
22
?
a
2
n
?
?
?
?
a
m
1
a
m
2
?
a
m
n
)
,
B
=
(
b
11
b
12
?
b
1
n
b
21
b
22
?
b
2
n
?
?
?
?
b
m
1
b
m
2
?
b
m
n
)
∈
P
m
×
n
\forall\boldsymbol{A}=\begin{pmatrix}a_{11}&a_{12}&\cdots&a_{1n}\\ a_{21}&a_{22}&\cdots&a_{2n}\\ \vdots&\vdots&\cdots&\vdots\\ a_{m1}&a_{m2}&\cdots&a_{mn}\end{pmatrix},\boldsymbol{B}=\begin{pmatrix}b_{11}&b_{12}&\cdots&b_{1n}\\ b_{21}&b_{22}&\cdots&b_{2n}\\ \vdots&\vdots&\cdots&\vdots\\ b_{m1}&b_{m2}&\cdots&b_{mn}\end{pmatrix}\in P^{m\times n}
?A=??????a11?a21??am1??a12?a22??am2???????a1n?a2n??amn????????,B=??????b11?b21??bm1??b12?b22??bm2???????b1n?b2n??bmn????????∈Pm×n,定义
A
\boldsymbol{A}
A与
B
\boldsymbol{B}
B的和为:
C
=
A
+
B
=
(
a
11
+
b
11
a
12
+
b
12
?
a
1
n
+
b
1
n
a
21
+
b
21
a
22
+
b
23
?
a
2
n
+
b
2
n
?
?
?
?
a
m
1
+
b
m
1
a
m
2
+
b
m
2
?
a
m
n
+
b
m
n
)
∈
P
m
×
n
.
\boldsymbol{C}=\boldsymbol{A}+\boldsymbol{B}=\begin{pmatrix}a_{11}+b_{11}&a_{12}+b_{12}&\cdots&a_{1n}+b_{1n}\\ a_{21}+b_{21}&a_{22}+b_{23}&\cdots&a_{2n}+b_{2n}\\ \vdots&\vdots&\cdots&\vdots\\ a_{m1}+b_{m1}&a_{m2}+b_{m2}&\cdots&a_{mn}+b_{mn}\end{pmatrix}\in P^{m\times n}.
C=A+B=??????a11?+b11?a21?+b21??am1?+bm1??a12?+b12?a22?+b23??am2?+bm2???????a1n?+b1n?a2n?+b2n??amn?+bmn????????∈Pm×n. 定义
λ
\lambda
λ与
A
\boldsymbol{A}
A的积:
λ
?
A
=
(
λ
a
11
λ
a
12
?
λ
a
1
n
λ
a
21
λ
a
22
?
λ
a
2
n
?
?
?
?
λ
a
m
1
λ
a
m
2
?
λ
a
m
n
)
.
\lambda\cdot\boldsymbol{A}=\begin{pmatrix}\lambda a_{11}&\lambda a_{12}&\cdots&\lambda a_{1n}\\ \lambda a_{21}&\lambda a_{22}&\cdots&\lambda a_{2n}\\ \vdots&\vdots&\cdots&\vdots\\ \lambda a_{m1}&\lambda a_{m2}&\cdots&\lambda a_{mn}\end{pmatrix}.
λ?A=??????λa11?λa21??λam1??λa12?λa22??λam2???????λa1n?λa2n??λamn????????. 数
λ
\lambda
λ与矩阵
A
\boldsymbol{A}
A的积常简记为
λ
A
\lambda\boldsymbol{A}
λA。矩阵的加法和数乘法统称为矩阵的线性运算。 在Python的numpy包中,表示两个同形(具有相同的行数和列数)2维数组的array对象,按元素运算实现矩阵的加法,数与数组的按元素乘法实现矩阵的数乘运算。 例1 实数域?上矩阵
A
=
(
1
2
3
4
5
6
)
\boldsymbol{A}=\begin{pmatrix}1&2&3\\4&5&6\end{pmatrix}
A=(14?25?36?),
B
=
(
6
5
4
3
2
1
)
\boldsymbol{B}=\begin{pmatrix}6&5&4\\3&2&1\end{pmatrix}
B=(63?52?41?),计算
A
+
B
\boldsymbol{A}+\boldsymbol{B}
A+B。
import numpy as np
A=np.array([[1, 2, 3],
[4, 5, 6]])
B=np.array([[6, 5, 4],
[3, 2, 1]])
print(A+B)
运行程序,输出
[[7 7 7]
[7 7 7]]
即
A
+
B
=
(
1
2
3
4
5
6
)
+
(
6
5
4
3
2
1
)
=
(
7
7
7
7
7
7
)
\boldsymbol{A}+\boldsymbol{B}=\begin{pmatrix}1&2&3\\4&5&6\end{pmatrix}+\begin{pmatrix}6&5&4\\3&2&1\end{pmatrix} =\begin{pmatrix}7&7&7\\7&7&7\end{pmatrix}
A+B=(14?25?36?)+(63?52?41?)=(77?77?77?)。 例2 我们知道
(
B
,
⊕
,
∧
)
(B,\oplus,\wedge)
(B,⊕,∧)构成一个域,其中
B
=
{
0
,
1
}
B=\{0,1\}
B={0,1},
⊕
\oplus
⊕和
∧
\wedge
∧分别表示比特异或运算和与运算(见博文《Python的位运算》)。分辨率为
m
×
n
m\times n
m×n的单色屏幕(黑白屏)可视为
B
B
B上的一个
m
×
n
m\times n
m×n矩阵
A
\boldsymbol{A}
A。 为檫除屏
A
\boldsymbol{A}
A上的画面,可以作运算
A
⊕
A
\boldsymbol{A}\oplus\boldsymbol{A}
A⊕A,也可以作运算
0
∧
A
0\wedge\boldsymbol{A}
0∧A。今设
8
×
8
8\times8
8×8单色屏上画面为 试用上述关于
B
n
×
n
B^{n\times n}
Bn×n上线性运算
⊕
\oplus
⊕和
∧
\wedge
∧的方法檫除画面。
import numpy as np
A=np.array([[0,0,1,1,1,1,0,0],
[0,1,0,0,0,0,1,0],
[1,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,1],
[0,1,0,0,0,0,1,0],
[0,0,1,1,1,1,0,0]])
print(A)
print(A^A)
print(0&A)
Python分别用“^”和“&”表示异或运算符
⊕
\oplus
⊕和与运算符
∧
\wedge
∧(见博文《Python的位运算》)。运行程序,输出
[[0,0,1,1,1,1,0,0],
[0,1,0,0,0,0,1,0],
[1,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,1],
[0,1,0,0,0,0,1,0],
[0,0,1,1,1,1,0,0]]
[[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]]
[[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]]
写博不易,敬请支持: 如果阅读本文于您有所获,敬请点赞、评论、收藏,谢谢大家的支持!
|