【发布时间】:2021-11-29 17:57:48
【问题描述】:
我使用 pytorch 编写了以下代码并遇到了运行时错误:
tns = torch.tensor([1,0,1])
tns.mean()
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-666-194e5ab56931> in <module>
----> 1 tns.mean()
RuntimeError: mean(): input dtype should be either floating point or complex dtypes. Got Long instead.
但是,如果我将张量更改为浮动,错误就会消失:
tns = torch.tensor([1.,0,1])
tns.mean()
---------------------------------------------------------------------------
tensor(0.6667)
我的问题是为什么会发生错误。第一个 Tenor 的数据类型是 int64 而不是 Long,为什么 PyTorch 把它当作 Long?
【问题讨论】: