<p dir="auto">This bug is probably reported or even fixed already.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import torch, numpy as np
x = np.random.randint(0, 1, [20]).astype('bool')
x_ft = torch.FloatTensor(x)     # corrupts data
assert all(x_ft.numpy() == x)  # fails"><pre class="notranslate"><code class="notranslate">import torch, numpy as np
x = np.random.randint(0, 1, [20]).astype('bool')
x_ft = torch.FloatTensor(x)     # corrupts data
assert all(x_ft.numpy() == x)  # fails
</code></pre></div>
<p dir="auto">Here's what x_ft looks like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; x_ft

 3.9404e-23
 4.5744e-41
 3.9404e-23
 4.5744e-41
-7.6586e+00
..."><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; x_ft

 3.9404e-23
 4.5744e-41
 3.9404e-23
 4.5744e-41
-7.6586e+00
...
</code></pre></div>
<p dir="auto">My torch versions</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; torch.__version__
'0.3.0.post4'
&gt;&gt;&gt; np.__version__
'1.14.0'"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; torch.__version__
'0.3.0.post4'
&gt;&gt;&gt; np.__version__
'1.14.0'
</code></pre></div>
<p dir="auto">OS: ubuntu 16<br>
PyTorch installation: linux, conda, py3.5, for cpu<br>
No cuda/GPU available<br>
cmake version 3.5.1</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; torch.Tensor(numpy.ndarray(shape=(2,2),dtype=&quot;int8&quot;))

 0.6229  0.0000
 0.0000  0.0000
[torch.FloatTensor of size 2x2]

&gt;&gt;&gt; torch.from_numpy(numpy.ndarray(shape=(2,2),dtype=&quot;int8&quot;))
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
RuntimeError: can't convert a given np.ndarray to a tensor - it has an invalid type. The only supported types are: double, float, int64, int32, and uint8."><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; torch.Tensor(numpy.ndarray(shape=(2,2),dtype="int8"))

 0.6229  0.0000
 0.0000  0.0000
[torch.FloatTensor of size 2x2]

&gt;&gt;&gt; torch.from_numpy(numpy.ndarray(shape=(2,2),dtype="int8"))
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
RuntimeError: can't convert a given np.ndarray to a tensor - it has an invalid type. The only supported types are: double, float, int64, int32, and uint8.
</code></pre></div>
<p dir="auto">According to <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/colesbury/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/colesbury">@colesbury</a>, however, it does look like ndarray passed into Tensor is doing the correct codepath.</p>
<p dir="auto">CC <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/aszlam/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/aszlam">@aszlam</a></p>