我使用 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.
Run Code Online (Sandbox Code Playgroud)
但是,如果我将张量更改为浮动,错误就会消失:
tns = torch.tensor([1.,0,1])
tns.mean()
---------------------------------------------------------------------------
tensor(0.6667)
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么会发生错误。第一个tenor的数据类型是int64而不是Long,为什么PyTorch将其视为Long?
| 归档时间: |
|
| 查看次数: |
10370 次 |
| 最近记录: |