python - scipy.stats 中支持 float128 (np.longdouble)

标签 python scipy precision long-double

我想使用 scipy.stats 进行一些概率计算,并避免下溢/溢出: 除了使用适当的日志函数之外,我还尝试使用 numpy.longdouble (Ubuntu 上的 float128)来提高浮点精度。

但是我尝试的功能都失败了,例如:

import numpy as np, scipy.stats as st
x = np.array([0.1, 0.2, 0.5], dtype=np.longdouble)
st.entropy(x)
st.gamma.pdf(x, 2)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-72225ce02b65> in <module>
----> 1 st.entropy(x)

~/.local/lib/python3.5/site-packages/scipy/stats/_distn_infrastructure.py in entropy(pk, qk, base, axis)
   2664     pk = 1.0*pk / np.sum(pk, axis=axis, keepdims=True)
   2665     if qk is None:
-> 2666         vec = entr(pk)
   2667     else:
   2668         qk = asarray(qk)

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

scipy.stats 中是否支持长 double ? 据此documentation page ,看来并非如此:-(

<小时/>

详细信息和版本

我的问题类似于 this one ,除了 scipy.linalg.svdmpmath.matrix 对我有用。

scipy 版本为 1.4.1,numpy.show_config():

lapack_opt_info:
    libraries = ['openblas', 'openblas']
    define_macros = [('HAVE_CBLAS', None)]
    language = c
    library_dirs = ['/usr/local/lib']
openblas_lapack_info:
    libraries = ['openblas', 'openblas']
    define_macros = [('HAVE_CBLAS', None)]
    language = c
    library_dirs = ['/usr/local/lib']
openblas_info:
    libraries = ['openblas', 'openblas']
    define_macros = [('HAVE_CBLAS', None)]
    language = c
    library_dirs = ['/usr/local/lib']
lapack_mkl_info:
  NOT AVAILABLE
blis_info:
  NOT AVAILABLE
blas_opt_info:
    libraries = ['openblas', 'openblas']
    define_macros = [('HAVE_CBLAS', None)]
    language = c
    library_dirs = ['/usr/local/lib']
blas_mkl_info:
  NOT AVAILABLE

最佳答案

基本上,不,没有。特定发行版的选择方法可能有效,也可能无效,并且不能保证。

关于python - scipy.stats 中支持 float128 (np.longdouble),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60184953/

相关文章:

python - Scipy ndimage 形态学运算符使我的计算机内存 RAM (8GB) 饱和

javascript - Node控制台如何显示 float

python - Django - NoReverseMatch。我忽略了什么?

javascript - 日期选择器未定义 - jQuery

python - 在 numpy 中减去数组并用 pylab 绘图

python - 在一个句子中找到相同的 2 个字符序列

python - scipy/numpy 中 matlab interp2 样条线的等效项

python - 高效构建 FEM/FVM 矩阵

tsql - T-SQL 小数除法精度

C++ 设置 double (不用于输出)