TypeError: ufunc ‘isinf‘ not supported for the input types, and the inputs could not be safely...

本文探讨了遇到的NumPy错误,当Table数据包含非数值类型(如字符串)时,如何通过删除这些数据来修复isinf函数的使用。关键步骤是识别问题并实施数据清理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 报错代码

    np.isinf(Table)
    
  • nmupy错误提示:

    TypeError: ufunc ‘isinf’ not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ‘‘safe’’

  • 原因
    Table 数据中存在非数值型的数据,比如str

  • 解决方法
    删除Table数据中的非数值型数据

Traceback (most recent call last): File "D:\35433\Documents\机器学习\任务二\任务二.py", line 89, in <module> contour = plt.contourf(xx, yy, Z, alpha=0.4, cmap='RdYlBu', levels=np.linspace(0,1,100)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python\Lib\site-packages\matplotlib\pyplot.py", line 3181, in contourf __ret = gca().contourf( ^^^^^^^^^^^^^^^ File "D:\python\Lib\site-packages\matplotlib\__init__.py", line 1521, in inner return func( ^^^^^ File "D:\python\Lib\site-packages\matplotlib\axes\_axes.py", line 6760, in contourf contours = mcontour.QuadContourSet(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python\Lib\site-packages\matplotlib\contour.py", line 708, in __init__ kwargs = self._process_args(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python\Lib\site-packages\matplotlib\contour.py", line 1326, in _process_args x, y, z = self._contour_args(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python\Lib\site-packages\matplotlib\contour.py", line 1370, in _contour_args z = ma.masked_invalid(z, copy=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python\Lib\site-packages\numpy\ma\core.py", line 2426, in masked_invalid res = masked_where(~(np.isfinite(a)), a, copy=copy) ^^^^^^^^^^^^^^ TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''报错
最新发布
03-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

szZack

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值