我尝试将提供任意精度算法的mpmath库和scipy.stats库结合使用:
from mpmath import mpf
from scipy.stats import norm
x = mpf(3) # arbitrary precision float
y = norm.cdf(x)但是,norm.cdf通过调用np.isnan(x)在内部检查其输入是否为数字。因此,我得到了以下错误:
Traceback (most recent call last):
File "name of my file", line 5, in <module>
y = norm.cdf(x)
File "C:\Program Files\Anaconda3\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 1734, in cdf
place(output, (1-cond0)+np.isnan(x), self.badvalue)
TypeError: ufunc 'isnan' 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.cdf使用mpmath.isnan而不是np.isnan?或者有其他方法来解决这个问题?
发布于 2017-01-18 11:55:21
mpmath为正态分布实现了自己的方法:mpdf and ncdf。
from mpmath import ncdf
y = ncdf(x) # returns mpf('0.9986501019683699')除了将mpf向下转换为常规浮点数之外,您不能使非mpmath方法与mpf对象一起工作。它们的底层计算例程被设计为以固定精度工作(通常在Fortran中),并且不知道如何处理mpf。这就是为什么mpmath重新实现了SciPy中已经存在的数学函数。
https://stackoverflow.com/questions/41707018
复制相似问题