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

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐