![](/img/trans.png)
[英]What does “ValueError: Domain error in arguments” refer to in stats.truncnorm.rvs?
[英]scip.stats.truncnorm — error using arrays for loc and scale
我想擾動假設正態分布的一組點。 我正在使用scipy.stats.truncnorm,因為我需要確保干擾點始終為正。 這是MWE:
import numpy as np
from scipy.stats import truncnorm
# Generate points to perturb
N = 100000
z = np.random.rand(N)
sigmaz = (z+1.0)*0.03
# Set limits for truncnorm
a = (0.0-z)/sigmaz
b = np.ones_like(z)*np.inf
# Set size -- want to sample once for each point
size = tuple(np.ones(len(z)))
print truncnorm.rvs(a=a,b=b,loc=z,scale=sigmaz,size=size)
但是,我收到以下錯誤:
Traceback (most recent call last):
File "./test.py", line 17, in <module>
print truncnorm.rvs(a=a,b=b,loc=z,scale=sigmaz,size=size)
File "/share/modules/install_dir/anaconda/lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.py", line 818, in rvs
cond = logical_and(self._argcheck(*args), (scale >= 0))
File "/share/modules/install_dir/anaconda/lib/python2.7/site-packages/scipy/stats/_continuous_distns.py", line 3796, 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,b都有各自不同的值?
還是有人知道在python中避免手動循環的另一種方法嗎?
非常感謝您提供的任何幫助!
這是一個已知的錯誤。 截斷的正態分布不接受類似數組的loc和scale。 大多數發行版都可以,但不是這一類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.