Name 'Tensor' is not defined

shangguan91: <p>i import Torch already, how come tensor is not defined.<br>
also tried from torch import tensor</p>

albanD: <p>Hi,</p>
<p>You might want to check a python tutorial on how to import libraries.<br>
But if you do:</p>
<pre><code class="lang-auto">import torch
torch.Tensor(xxx)
</code></pre>
<p>This will work.</p>

shangguan91: <p>i am sure that i corretly import all libraries.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/6/e6d1bf439fcfd4463d548140ce82ca26542b61bd.png" data-download-href="https://discuss.pytorch.org/uploads/default/e6d1bf439fcfd4463d548140ce82ca26542b61bd" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/e/6/e6d1bf439fcfd4463d548140ce82ca26542b61bd.png" alt="image" data-base62-sha1="wVVcmi3YzAnLaJPgznVh1lTGrgN" width="690" height="385" data-dominant-color="F7F7F9"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">907×507 21.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

albanD: <p>In that file you access <code>Tensor</code> and not <code>torch.Tensor</code>. So for that to work, if you want a pytorch Tensor, you need to have <code>from torch import Tensor</code> (capital T) in that file.</p>

shangguan91: <aside class="quote no-group" data-username="albanD" data-post="4" data-topic="90710">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/alband/48/215_2.png" class="avatar"> albanD:</div>
<blockquote>
<p>from torch import Tensor</p>
</blockquote>
</aside>
<p>still wont work<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/1/412a136458975fc9bfd4902d02241c95f6587837.png" data-download-href="https://discuss.pytorch.org/uploads/default/412a136458975fc9bfd4902d02241c95f6587837" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/4/1/412a136458975fc9bfd4902d02241c95f6587837_2_690x312.png" alt="image" data-base62-sha1="9itbjmL2JM0dyKuphTVboo1BA59" width="690" height="312" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/4/1/412a136458975fc9bfd4902d02241c95f6587837_2_690x312.png, https://discuss.pytorch.org/uploads/default/optimized/3X/4/1/412a136458975fc9bfd4902d02241c95f6587837_2_1035x468.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/4/1/412a136458975fc9bfd4902d02241c95f6587837_2_1380x624.png 2x" data-dominant-color="F5F5F7"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1547×701 53.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

albanD: <p>That is surprising. Do you delete it later?<br>
If you have just this import and this call. This will work fine.</p>

Santosh_Sahu: <p>Use torch.<strong>t</strong>ensor(1)<br>
instead of torch.Tensor(1)</p>