马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#dataframe转化为tensor
#将DataFrame数据转换为NumPy数组,然后再转换为PyTorch张量
X_train = torch.tensor(X_train.astype(np.float32).values, dtype=torch.float32).cuda()
y_train = torch.tensor(y_train.astype(np.float32).values, dtype=torch.float32)
X_valid = torch.tensor(X_val.astype(np.float32).values, dtype=torch.float32)
y_valid = torch.tensor(y_val.astype(np.float32).values, dtype=torch.float32)
上述代码报错---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[46], line 3
1 #dataframe转化为tensor
2 #将DataFrame数据转换为NumPy数组,然后再转换为PyTorch张量
----> 3 X_train = torch.tensor(X_train.astype(np.float32).values, dtype=torch.float32).cuda()
4 y_train = torch.tensor(y_train.astype(np.float32).values, dtype=torch.float32)
5 X_valid = torch.tensor(X_val.astype(np.float32).values, dtype=torch.float32)
AttributeError: 'Tensor' object has no attribute 'astype'
|