torch7

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]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值