擅长:python、mysql、java
<p>尝试<a href="https://pytorch.org/docs/stable/torch.html#torch.reshape" rel="nofollow noreferrer">^{<cd1>}</a>您需要将<code>s</code>的形状更改为<code>(1,2)</code>,以便能够使用<code>(2,2)</code>张量进行<a href="https://pytorch.org/docs/stable/torch.html#torch.mm" rel="nofollow noreferrer">matrix multiplication</a>运算</p>
<pre class="lang-py prettyprint-override"><code>>>> s.reshape(1,2).mm(x)
tensor([[0.0700, 0.1000]], dtype=torch.float64, grad_fn=<MmBackward>)
</code></pre>
<p>或者在初始化<code>s</code>时给出正确的形状</p>
<pre class="lang-py prettyprint-override"><code>>>> s = Variable(torch.DoubleTensor([[0.01,0.02]]),requires_grad = True)
>>> s.mm(x)
tensor([[0.0700, 0.1000]], dtype=torch.float64, grad_fn=<MmBackward>)
</code></pre>