【发布时间】:2015-04-24 07:35:26
【问题描述】:
所以我需要使用 Python 中的 truncnorm 函数来评估下限为零的截断正态分布中值的可能性。
由于truncnorm 适用于标准正态分布,如果您使用自己的mu 和sigma 参数,则必须重新参数化a 和b。 a 和 b 写成 (myclip - mu) / sigma
我需要在mu 和sigma 的不同参数化下一次评估多个值,这意味着我必须将数组作为a 和b 的参数。但是,每次我这样做时都会收到一条错误消息。一些简化的示例代码如下:
import numpy as np
from scipy.stats import truncnorm
v = np.array([5, 4])
mus = np.ones(2)
sigmas = np.ones(2)
a = (0 - mus) / sigmas
b = np.ones(2) * np.inf
like = truncnorm.pdf(vals, a, b, mus, sigmas)
我收到此错误消息:
cond0 = self._argcheck(*args) & (scale > 0)
File "/Users/adamosth/anaconda/lib/python2.7/sitepackages/scipy/stats/_continuous_distns.py", line 3818, in _argcheck
if self.a > 0:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
如果a 作为单个值输入,我没有问题,但这并不是我真正想要的。
【问题讨论】: