【异常】TypeError: can't convert np.ndarray of type numpy.object_. The only supported types are: double,

当尝试将np.ndarray对象转换时遇到错误:'TypeError: can't convert np.ndarray of type numpy.object_. The only supported types are: double, float, float16, int64, int32, and uint8.'。问题源于数据集生成过程中的数据形状不正确。在getAllData.py中,由于筛选操作导致元素长度不一致,修正方法是在创建二维list时确保所有元素长度相同。通过限制X的长度为100,解决了输入数据长度不一的问题,从而避免了torch数据加载时的错误。" 18733817,351306,Linux Xen 恢复virbr0网络接口,"['Linux系统管理', '虚拟化', '网络配置', 'virsh命令']
摘要由CSDN通过智能技术生成

1. 问题:

TypeError: can’t convert np.ndarray of type numpy.object_. The only supported types are: double, float, float16, int64, int32, and uint8.

2. 异常代码行:

train_x = torch.from_numpy(train_x).float().unsqueeze(1)  # numpy 转成 torch 类型

3. 相关代码:

train.py

from getData import getAllData
from sklearn.model_selection import train_test_split

data = getAllData()
X, Y = data.XY()
print(type(X))  # <class 'list'>
print(np.shape
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值