回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我面临着pythorch不一致的行为,根据weither的说法,索引是一个列表或整数。请看以下代码片段:</p>
<pre><code># First example, integer selector ==> Ok
t = torch.tensor([[0, 1], [1, 0]])
t[0, 0].add_(10)
print(t)
tensor([[10, 1],
[ 1, 0]])
# Second example, list selector ==> ???
t = torch.tensor([[0, 1], [1, 0]])
t[[0], [0]].add_(10) # notice the list selector
print(t)
tensor([[0, 1],
[1, 0]])
#Third example, list selector with inplace add operator ==> Ok
t = torch.tensor([[0, 1], [1, 0]])
t[[0], [0]] += 10
print(t)
tensor([[10, 1],
[ 1, 0]])
</code></pre>
<p>我不明白为什么在第二个例子中<code>pytorch</code>无法更新<code>t</code>!你知道吗</p>