擅长:python、mysql、java
<p>只需循环使用张量并进行比较:</p>
<pre><code>require 'torch'
data = torch.Tensor({1,2,3,4,505,6,7,8,9,10,11,12})
idx = 1
max = data[1]
for i=1,data:size()[1] do
if data[i]>max then
max=data[i]
idx=i
end
end
print(idx,max)
</code></pre>
<p>编辑
响应您的编辑:使用此处记录的torch.max操作:<a href="https://github.com/torch/torch7/blob/master/doc/maths.md#torchmaxresval-resind-x-dim" rel="nofollow">https://github.com/torch/torch7/blob/master/doc/maths.md#torchmaxresval-resind-x-dim</a></p>
<pre><code>y, i = torch.max(x, 1) returns the largest element in each column (across rows) of x, and a Tensor i of their corresponding indices in x
</code></pre>