TypeError: can't convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.解决办法


问题描述

在讲dataframe中的列表数据制作成数据集是,报错TypeError: can’t convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.
原来的数据格式是这样的:样本有1044列,每一条数据有1024个采样点,每一行代表一个样本。
在这里插入图片描述

解决办法

原来的

dat_dict["samples"] = torch.from_numpy(X_train)

修改之后

dat_dict["samples"] = torch.tensor([item for item in X_train])

最终转换成这种形式
在这里插入图片描述

就成功了!

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐