是否可以将数字设置为NaN或无穷大? [英] Is it possible to set a number to NaN or infinity?

查看:170
本文介绍了是否可以将数字设置为NaN或无穷大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Python中将数组的元素设置为NaN?

Is it possible to set an element of an array to NaN in Python?

此外,是否可以将变量设置为+/-无穷大?如果是这样,是否有任何功能可以检查数字是否为无穷大?

Additionally, is it possible to set a variable to +/- infinity? If so, is there any function to check whether a number is infinity or not?

推荐答案

使用float()从字符串中投射:

>>> float('NaN')
nan
>>> float('Inf')
inf
>>> -float('Inf')
-inf
>>> float('Inf') == float('Inf')
True
>>> float('Inf') == 1
False

这篇关于是否可以将数字设置为NaN或无穷大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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