<p>在张量构造过程中未指定<code>dtype</code>时,<a href="https://pytorch.org/docs/stable/tensors.html#torch-tensor" rel="noreferrer">^{<cd1>} is just an alias to ^{<cd2>}</a>是张量的默认类型。</p>
<p>从<a href="https://github.com/torch/torch7/wiki/Torch-for-Numpy-users#ones-and-zeros" rel="noreferrer">torch for numpy users notes</a>来看,似乎<code>torch.Tensor()</code>是<code>numpy.empty()</code>的替代品</p>
<p>因此,本质上<code>torch.FloatTensor()</code>和<code>torch.empty()</code>做的是返回一个由dtype<code>torch.float32</code>的垃圾值填充的张量。下面是一个小跑步:</p>
<pre><code>In [87]: torch.FloatTensor(2, 3)
Out[87]:
tensor([[-1.0049e+08, 4.5688e-41, -8.9389e-38],
[ 3.0638e-41, 4.4842e-44, 0.0000e+00]])
In [88]: torch.FloatTensor(2, 3)
Out[88]:
tensor([[-1.0049e+08, 4.5688e-41, -1.6512e-38],
[ 3.0638e-41, 4.4842e-44, 0.0000e+00]])
</code></pre>
<hr/>
<pre><code>In [89]: torch.empty(2, 3)
Out[89]:
tensor([[-1.0049e+08, 4.5688e-41, -9.0400e-38],
[ 3.0638e-41, 4.4842e-44, 0.0000e+00]])
In [90]: torch.empty(2, 3)
Out[90]:
tensor([[-1.0049e+08, 4.5688e-41, -9.2852e-38],
[ 3.0638e-41, 4.4842e-44, 0.0000e+00]])
</code></pre>