学无先后,达者为师

网站首页 编程语言 正文

RuntimeError: scatter(): Expected dtype int64 for index

作者:甘霖佳佳 更新时间: 2022-01-31 编程语言

在这里插入图片描述
RuntimeError: scatter(): Expected dtype int64 for index

1.报错原因:

scatter要求数据是int64类型,而我在定义tensor时写的是torch.Tensor(x),应该写成torch.LongTensor(x),指定为int64类型。

2.解决方法

找到原数据的定义方式,改!
一般在dtype=np.int64;dtype=np.float32中
(多数定义函数都有dtype属性)
最好int和float的位数要一致

import numpy as np
a = np.random.randint(100, size=(10**6), dtype="int64")
print(a)
print(type(a[0]))

在这里插入图片描述

原文链接:https://blog.csdn.net/weixin_45928096/article/details/122387959

栏目分类
最近更新