当前位置:网站首页>"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.3 linear algebra_ Learning thinking and exercise answers
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.3 linear algebra_ Learning thinking and exercise answers
2022-07-06 02:31:00 【coder_ sure】
List of articles
2.3 linear algebra
author github link : github link
practice
- Prove a matrix A \mathbf{A} A The transpose of is A \mathbf{A} A, namely ( A ⊤ ) ⊤ = A (\mathbf{A}^\top)^\top = \mathbf{A} (A⊤)⊤=A.
- Two matrices are given A \mathbf{A} A and B \mathbf{B} B, prove “ They are transposed and ” be equal to “ They are transposed with ”, namely A ⊤ + B ⊤ = ( A + B ) ⊤ \mathbf{A}^\top + \mathbf{B}^\top = (\mathbf{A} + \mathbf{B})^\top A⊤+B⊤=(A+B)⊤.
- Given an arbitrary square matrix A \mathbf{A} A, A + A ⊤ \mathbf{A} + \mathbf{A}^\top A+A⊤ Is it always symmetrical ? Why? ?
- We define shapes in this section ( 2 , 3 , 4 ) (2,3,4) (2,3,4) Tensor
X
.len(X)
What is the output of ? - For tensors of arbitrary shape
X
,len(X)
Whether it always corresponds toX
The length of a particular axis ? What is this axis ? - function
A/A.sum(axis=1)
, See what happens . Can you analyze the reason ? - Consider a with a shape ( 2 , 3 , 4 ) (2,3,4) (2,3,4) Tensor , In the shaft 0、1、2 What shape is the summation output on ?
- by
linalg.norm
Function provides 3 Tensors of one or more axes , And observe its output . For tensors of any shape, what does this function calculate ?
Practice reference answers ( If there is a mistake , Please also correct )
1. Prove a matrix A \mathbf{A} A The transpose of is A \mathbf{A} A, namely ( A ⊤ ) ⊤ = A (\mathbf{A}^\top)^\top = \mathbf{A} (A⊤)⊤=A.
A·=·torch.arange(12).reshape(3,4)A,(A.T).T
output:
(tensor([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]]), tensor([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]]))
2. Two matrices are given A \mathbf{A} A and B \mathbf{B} B, prove “ They are transposed and ” be equal to “ They are transposed with ”, namely A ⊤ + B ⊤ = ( A + B ) ⊤ \mathbf{A}^\top + \mathbf{B}^\top = (\mathbf{A} + \mathbf{B})^\top A⊤+B⊤=(A+B)⊤.
B = torch.tensor([[9, 8, 7,6], [5, 4, 3,2], [3, 4, 5,1]])
A.T+B.T ,(A+B).T
output:
(tensor([[ 9, 9, 11],
[ 9, 9, 13],
[ 9, 9, 15],
[ 9, 9, 12]]), tensor([[ 9, 9, 11],
[ 9, 9, 13],
[ 9, 9, 15],
[ 9, 9, 12]]))
3. Given an arbitrary square matrix A \mathbf{A} A, A + A ⊤ \mathbf{A} + \mathbf{A}^\top A+A⊤ Is it always symmetrical ? Why? ?
answer : because ( A + A ⊤ ) ⊤ = A ⊤ + A = A + A ⊤ (\mathbf{A} + \mathbf{A}^\top)^\top=\mathbf{A}^\top+\mathbf{A}=\mathbf{A} + \mathbf{A}^\top (A+A⊤)⊤=A⊤+A=A+A⊤
A = torch.arange(9).reshape(3,3)
A
output:
tensor([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
A+A.T
output:
tensor([[ 0, 4, 8],
[ 4, 8, 12],
[ 8, 12, 16]])
4. We define shapes in this section ( 2 , 3 , 4 ) (2,3,4) (2,3,4) Tensor X
.len(X)
What is the output of ?
X = torch.arange(24).reshape(2, 3, 4)
len(X)
output:
2
5. For tensors of arbitrary shape X
,len(X)
Whether it always corresponds to X
The length of a particular axis ? What is this axis ?
answer :len(X) Total correspondence No 0 Length of shaft .
6. function A/A.sum(axis=1)
, See what happens . Can you analyze the reason ?
answer : Unable to run , as a result of A It's a 5 * 4 Matrix , and A.sum(axis=1) It's a flattened 1 Dimension vector , The two dimensions do not match and cannot be divided .( notes : Broadcasting can only happen when the two dimensions are the same , For example, they are all two-dimensional )
A = torch.arange(20, dtype=torch.float32).reshape(5, 4)
A/A.sum(axis=1,keepdims=True)
output:
tensor([[0.0000, 0.1667, 0.3333, 0.5000],
[0.1818, 0.2273, 0.2727, 0.3182],
[0.2105, 0.2368, 0.2632, 0.2895],
[0.2222, 0.2407, 0.2593, 0.2778],
[0.2286, 0.2429, 0.2571, 0.2714]])
A = torch.arange(20, dtype=torch.float32).reshape(5, 4)
A/A.sum(axis=1)
output:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-59-86c8759e15d3> in <module>()
1 A = torch.arange(20, dtype=torch.float32).reshape(5, 4)
----> 2 A/A.sum(axis=1)
RuntimeError: The size of tensor a (4) must match the size of tensor b (5) at non-singleton dimension 1
7. Consider a with a shape ( 2 , 3 , 4 ) (2,3,4) (2,3,4) Tensor , In the shaft 0、1、2 What shape is the summation output on ?
H=torch.arange(24).reshape(2,3,4)
H
output:
tensor([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
H0 = H.sum(axis=0)
H1 = H.sum(axis=1)
H2 = H.sum(axis=2)
H0, H1, H2
output:
(tensor([[12, 14, 16, 18],
[20, 22, 24, 26],
[28, 30, 32, 34]]), tensor([[12, 15, 18, 21],
[48, 51, 54, 57]]), tensor([[ 6, 22, 38],
[54, 70, 86]]))
8. by linalg.norm
Function provides 3 Tensors of one or more axes , And observe its output . For tensors of any shape, what does this function calculate ?
answer : In fact, it is the operation of finding norms ( The default is 2 norm )
Z=torch.ones(2,3,4)
W=torch.ones(2,2,3,4)
torch.norm(Z)*torch.norm(Z),torch.norm(W)*torch.norm(W)
output:
(tensor(24.0000), tensor(48.))
边栏推荐
- Overview of spark RDD
- MySQL winter vacation self-study 2022 11 (7)
- [robot library] awesome robots Libraries
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
- HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
- LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5
- Prepare for the autumn face-to-face test questions
- After changing the GCC version, make[1] appears in the compilation: cc: command not found
- The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
猜你喜欢
2022 China eye Expo, Shandong vision prevention and control exhibition, myopia, China myopia correction Exhibition
Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
Httprunnermanager installation (III) - configuring myql Database & initialization data under Linux
零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器
Easy to use js script
Concept of storage engine
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022
[postgraduate entrance examination English] prepare for 2023, learn list5 words
随机推荐
Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle
Sword finger offer 30 Stack containing min function
Use Scrollview and tabhost to realize vertical scrollbars and tabs
Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械
MySQL winter vacation self-study 2022 11 (5)
vs code保存时 出现两次格式化
I changed the driver to 5.1.35, but it is still the same error. I can succeed even now, but I will report this every time I do an SQL operation
HDU_ p1237_ Simple calculator_ stack
Method of changing object properties
Looking at the trend of sequence modeling of recommended systems in 2022 from the top paper
Advanced technology management - what is the physical, mental and mental strength of managers
Multi function event recorder of the 5th National Games of the Blue Bridge Cup
550 permission denied occurs when FTP uploads files, which is not a user permission problem
MySQL winter vacation self-study 2022 11 (9)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
UE4 - how to make a simple TPS role (I) - create a basic role
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
【MySQL 15】Could not increase number of max_open_files to more than 10000 (request: 65535)
What should we pay attention to when using the built-in tool to check the health status in gbase 8C database?
零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器