python - 提高 float 的准确性

标签 python numpy

<分区>

如何将默认 float 精度切换为另一个精度,也许是自定义精度?我需要这个,因为我做了一些计算,我发现我应该提高默认的浮点精度。

最佳答案

我最近不得不处理这个问题和 mpmath很完美。它是纯 Python,遵循 BSD 许可。

Mpmath is a pure-Python library for multiprecision floating-point arithmetic. It provides an extensive set of transcendental functions, unlimited exponent sizes, complex numbers, interval arithmetic, numerical integration and differentiation, root-finding, linear algebra, and much more. Almost any calculation can be performed just as well at 10-digit or 1000-digit precision, and in many cases mpmath implements asymptotically fast algorithms that scale well for extremely high precision work

它并没有慢很多,而且它可以利用 gmpy如果安装了库(支持快速多精度算术的 C 编码 Python 扩展模块)。

关于python - 提高 float 的准确性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13442531/

相关文章:

Python:如何读取列数不均匀的数据文件

python - 使用字符串和整数从 Numpy 中的列表创建结构体数组

python - 如何从一串数字和逗号中挑选出数百万?

python - 如何将 python 列表的所有子集放入 n 个容器中

python - 如何从 OpenCV Python 中的特征匹配中获取像素坐标

python - 在 PYTHON 中求解矩阵耦合微分方程时如何绘制特征值?

python - 获取不属于不同模型的多对多关系的对象?

python - 类中每个方法的标准日志记录

python - 数组的分布图

python - 在 numpy 2D 矩阵中计算 "wells"