Skip to content

Commit f4db9fa

Browse files
authored
Update pytorch.md
1 parent 612dcb6 commit f4db9fa

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pytorch.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ Today read Chapter 5. Have learned the mechanics of learning.
66
## basic torch operation
77
- \* / mul 对应位的元素直接乘(broadcast参看boradcast的说明)
88
- mm / matmul 矩阵乘
9+
- unsqueeze(input, dim)
10+
11+
在dim处插入一维 [1,2,3,4], dim=0 => [[1,2,3,4]]; dim=1 =>[[1],[2],[3],[4]]
12+
src shape是(4), dim=0时,shape为(1,4); dim=1时,shape为(4,1)
13+
- view(*shape)
14+
15+
参数中-1表示根据其它维数,算出剩余的维数。比如:
16+
17+
```python
18+
x = torch.randn(4,4)
19+
torch.Size([4,4])
20+
y = x.view(-1,2)
21+
torch.Size([8,2])
22+
z = x.view(-1)
23+
torch.Size([16])
24+
```
25+
926
- concat
1027
- stack
1128

0 commit comments

Comments
 (0)