【发布时间】:2021-05-29 07:16:20
【问题描述】:
当我尝试运行以下简单行时,我遇到了一个非常奇怪的错误:
a = torch.Tensor([0,0,0],dtype = torch.int64)
TypeError: new() received an invalid combination of arguments - got (list, dtype=torch.dtype), but expected one of:
* (*, torch.device device)
didn't match because some of the keywords were incorrect: dtype
* (torch.Storage storage)
* (Tensor other)
* (tuple of ints size, *, torch.device device)
* (object data, *, torch.device device)
如果我们查看官方文档
torch.tensor(data, dtype=None, device=None, requires_grad=False, pin_memory=False) → Tensor
参数
data (array_like) – 张量的初始数据。可以是一个 列表、元组、NumPy ndarray、标量和其他类型。
dtype (torch.dtype, optional) – 返回的所需数据类型 张量。默认值:如果为 None,则从数据中推断数据类型。
为什么官方文档支持sn-p代码却不起作用?
【问题讨论】: