日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

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

欄目分類
最近更新