Nan to Num Python [英] Nan to Num Python

查看:382
本文介绍了Nan to Num Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个用于计算线性回归的数组,但有时它会给我0/0值,这给了我'NaN'.我知道要在存在NaN的数字的情况下转换数组,可以使用 numpy.nan_to_num .但是,如果我要转换单个值不在数组中,而是线性回归

I have multiple array that for those I calculate a linear regression, but sometimes it gives me 0/0 values which gives me a 'NaN'. I know that to convert an array where there are numbers that are NaN you can convert them using numpy.nan_to_num. But what if I want to convert a single value that's not in a array, but a result of a linear regression calculation?

这不是重复的问题(将nan值转换为零),因为我指的是不在数组中的项目/结果

It's not a duplicate question (convert nan value to zero ) since I'm referring to a item/result that is not in a array

推荐答案

numpy.nan_to_num在标量上工作正常.

>>> import numpy as np
>>> np.nan_to_num(float('inf'))
1.7976931348623157e+308
>>> np.nan_to_num(float('nan'))
0.0
>>> np.nan_to_num(float('-inf'))
-1.7976931348623157e+308

这篇关于Nan to Num Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆