问题描述
使用LSTM进行数据训练时出现此报错,将numpy的数据直接转成torch中的tensor数据类型
RuntimeError: expected scalar type Double but found Float
原因分析:
tensor的数据类型不正确
x_train_tensor = torch.from_numpy(x_train) y_train_tensor = torch.from_numpy(y_train)
解决方案:
将原来的tensor转成torch.float32类型即可
x_train_tensor = torch.from_numpy(x_train).to(torch.float32) y_train_tensor = torch.from_numpy(y_train).to(torch.float32)