torch7

文章目录

  • torch.max
  • tensor元素读取

torch.max

格式:
torch.max(input, dim, keepdim=False, out=None) -> (Tensor, LongTensor)

th> a=torch.rand(2,3)

 0.1055  0.5020  0.1127
 0.4437  0.4049  0.6918
[torch.DoubleTensor of size 2x3]

th> torch.max(a) --a中最大值

0.69182460033335

th> torch.max(a,1) --返回每一列中最大值的那个元素,且返回索引

0.4437  0.5020  0.6918
[torch.DoubleTensor of size 1x3]
 2  1  2
[torch.LongTensor of size 1x3]

th> torch.max(a,2)–返回每一行中最大值的那个元素,且返回索引

0.5020
0.6918
[torch.DoubleTensor of size 2x1]
2
3
[torch.LongTensor of size 2x1]

th> b=torch.rand(2,3,3)

(1,.,.) =
  0.2968  0.2864  0.0240
  0.0565  0.6799  0.5388
  0.4088  0.4470  0.1924
(2,.,.) =
  0.9951  0.4827  0.7110
  0.1648  0.8386  0.2206
  0.9690  0.0007  0.6369
[torch.DoubleTensor of size 2x3x3]

th> torch.max(b)

0.99509069975466

th> torch.max(b,1)

(1,.,.) =
  0.9951  0.4827  0.7110
  0.1648  0.8386  0.5388
  0.9690  0.4470  0.6369
[torch.DoubleTensor of size 1x3x3]
(1,.,.) =
  2  2  2
  2  2  1
  2  1  2
[torch.LongTensor of size 1x3x3]

th> torch.max(b,2)

(1,.,.) =
  0.4088  0.6799  0.5388
(2,.,.) =
  0.9951  0.8386  0.7110
[torch.DoubleTensor of size 2x1x3]
(1,.,.) =
  3  2  2
(2,.,.) =
  1  2  1
[torch.LongTensor of size 2x1x3]

tensor元素读取

th> a= torch.rand(2,3)
th>a
 0.9646  0.2998  0.8082
 0.4970  0.5252  0.2022
[torch.DoubleTensor of size 2x3]

th> a[1]  --[] 
 0.9646
 0.2998
 0.8082
[torch.DoubleTensor of size 3]

th> a[{{1}}]   --[{}]
 0.9646  0.2998  0.8082
[torch.DoubleTensor of size 1x3]

th> a[{{1},{2}}]
 0.2998
[torch.DoubleTensor of size 1x1]

th> b=torch.rand(2,3,4)
th> b
(1,.,.) =
  0.5474  0.4723  0.0516  0.0136
  0.9878  0.3986  0.0787  0.0547
  0.8163  0.7833  0.3281  0.8037
(2,.,.) =
  0.1795  0.4234  0.5883  0.4228
  0.3473  0.3866  0.3203  0.3479
  0.9887  0.4204  0.4081  0.0496
[torch.DoubleTensor of size 2x3x4]

th> b[{{1}}]
(1,.,.) =
  0.5474  0.4723  0.0516  0.0136
  0.9878  0.3986  0.0787  0.0547
  0.8163  0.7833  0.3281  0.8037
[torch.DoubleTensor of size 1x3x4]

th> b[{{},{2}}]
(1,.,.) =
  0.9878  0.3986  0.0787  0.0547
(2,.,.) =
  0.3473  0.3866  0.3203  0.3479
[torch.DoubleTensor of size 2x1x4]

th> b[{{1},{2},{3}}]
(1,.,.) =
 0.01 *
   7.8706
[torch.DoubleTensor of size 1x1x1]

你可能感兴趣的:(Torch)