VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tupl

文章讲述了在Python中遇到VisibleDeprecationWarning警告的原因,该警告出现在尝试从不同长度或形状的序列创建NumPy数组时。解决方案是通过指定dtype=object来创建数组。示例代码展示了如何修正这个问题,以避免警告并正确转换数据。
摘要由CSDN通过智能技术生成

报错信息:VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. Y_new = [np.squeeze(np.array(Y_new)).transpose()] # the aggregate output of 24 single outputs# 24个单独输出的聚合输出

 解释原因:

警告信息是VisibleDeprecationWarning,它与从不规则嵌套序列(即长度或形状不同的列表、元组或ndarray的列表或元组)创建NumPy数组有关。警告建议在创建ndarray时,如果你打算这样做,必须指定dtype=object

试图使用np.array(Y_new)Y_new转换为NumPy数组。然而,由于Y_new中的元素具有不同的长度或形状,这触发了这个警告。

为了解决这个警告并创建ndarray,在调用np.array()时通过指定dtype参数为'object'来进行设置。

 找到对应的行

Y_new = [np.squeeze(np.array(Y_new).transpose()]

改成

Y_new = [np.squeeze(np.array(Y_new, dtype=object)).transpose()]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值