<h2 dir="auto"><g-emoji class="g-emoji" alias="bug" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f41b.png">🐛</g-emoji> Bug</h2>
<p dir="auto">Using a numpy array <code class="notranslate">i</code> as index for a torch tensor <code class="notranslate">t</code> (i.e. <code class="notranslate">t[i]</code>) is interpreted differently than indexing a numpy array with the same index, or indexing t with the index converted to a tensor.</p>
<h2 dir="auto">To Reproduce</h2>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import torch
import numpy as np

a=np.array([0.])
t=torch.tensor([0.])
i=np.array([[0,0],[0,0]])
a[i] # Fine
t[torch.tensor(i)] # Fine
t[i] # IndexError: too many indices for tensor of dimension 1"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">torch</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-s1">a</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">0.</span>])
<span class="pl-s1">t</span><span class="pl-c1">=</span><span class="pl-s1">torch</span>.<span class="pl-en">tensor</span>([<span class="pl-c1">0.</span>])
<span class="pl-s1">i</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-en">array</span>([[<span class="pl-c1">0</span>,<span class="pl-c1">0</span>],[<span class="pl-c1">0</span>,<span class="pl-c1">0</span>]])
<span class="pl-s1">a</span>[<span class="pl-s1">i</span>] <span class="pl-c"># Fine</span>
<span class="pl-s1">t</span>[<span class="pl-s1">torch</span>.<span class="pl-en">tensor</span>(<span class="pl-s1">i</span>)] <span class="pl-c"># Fine</span>
<span class="pl-s1">t</span>[<span class="pl-s1">i</span>] <span class="pl-c"># IndexError: too many indices for tensor of dimension 1</span></pre></div>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto">I expected the last line to behave the same as the previous two.</p>
<h2 dir="auto">Environment</h2>
<p dir="auto">PyTorch version: 1.4.0<br>
Is debug build: No<br>
CUDA used to build PyTorch: 10.1</p>
<p dir="auto">OS: Debian GNU/Linux bullseye/sid<br>
GCC version: (Debian 9.2.1-30) 9.2.1 20200224<br>
CMake version: version 3.16.3</p>
<p dir="auto">Python version: 3.7<br>
Is CUDA available: Yes<br>
CUDA runtime version: 10.1.168<br>
GPU models and configuration: GPU 0: Quadro M2000M<br>
Nvidia driver version: 440.64<br>
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5</p>
<p dir="auto">Versions of relevant libraries:<br>
[pip3] numpy==1.17.4<br>
[pip3] numpydoc==0.7.0<br>
[pip3] torch==1.4.0<br>
[pip3] torchvision==0.5.0<br>
[conda] Could not collect</p>
<h2 dir="auto">Additional context</h2>
<p dir="auto">This appears related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="458367111" data-permission-text="Title is private" data-url="https://github.com/pytorch/pytorch/issues/22013" data-hovercard-type="issue" data-hovercard-url="/pytorch/pytorch/issues/22013/hovercard" href="https://github.com/pytorch/pytorch/issues/22013">#22013</a> and <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="520591820" data-permission-text="Title is private" data-url="https://github.com/pytorch/pytorch/issues/29522" data-hovercard-type="issue" data-hovercard-url="/pytorch/pytorch/issues/29522/hovercard" href="https://github.com/pytorch/pytorch/issues/29522">#29522</a> (possibly <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="426927315" data-permission-text="Title is private" data-url="https://github.com/pytorch/pytorch/issues/18616" data-hovercard-type="issue" data-hovercard-url="/pytorch/pytorch/issues/18616/hovercard" href="https://github.com/pytorch/pytorch/issues/18616">#18616</a>). If a numpy array is treated as an arbitrary Iterable, it is probably a duplicate of one of those, although there is the possibility of handling array-like types differently. I am reporting this because I am not sure the issue is exactly the same, but please don't hesitate to close this issue if it is redundant.</p>
<h2 dir="auto"><g-emoji class="g-emoji" alias="books" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f4da.png">📚</g-emoji> Documentation</h2>
<p dir="auto">The docs for <a href="https://pytorch.org/docs/master/tensors.html#torch.Tensor.index_put_" rel="nofollow">index_put_</a> state in the second paragraph:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="If accumulate is True, the elements in tensor are added to self. If accumulate is False, the behavior is undefined if indices contain duplicate elements."><pre class="notranslate"><code class="notranslate">If accumulate is True, the elements in tensor are added to self. If accumulate is False, the behavior is undefined if indices contain duplicate elements.
</code></pre></div>
<p dir="auto">It should be corrected to <code class="notranslate">elements in _value_ are added to self</code>.</p>