比较浮点数与 numpy 和 scipy [英] Comparing floating point numbers with numpy and scipy

查看:43
本文介绍了比较浮点数与 numpy 和 scipy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

numpy 或 scipy 模块中是否有任何 epsilon 常量(如在 Matlab 中)来比较浮点数?

解决方案

您可以使用 np.finfo

<预><代码>>>>将 numpy 导入为 np>>>np.finfo(np.double).eps2.2204460492503131e-16>>>np.finfo(np.single).eps1.1920929e-07

Is there any epsilon constant (as in Matlab) in numpy or scipy modules to compare floating point numbers?

解决方案

You can use np.finfo

>>> import numpy as np
>>> np.finfo(np.double).eps
2.2204460492503131e-16
>>> np.finfo(np.single).eps
1.1920929e-07

这篇关于比较浮点数与 numpy 和 scipy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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