如何从一个辣.stats获取分发名称。冷冻配送?

时间:2016-05-29 15:01:37

标签: python random scipy distribution

访问冻结分发的名称

frozen distribution包创建scipy.stats时,如果分发实例被冻结,如何访问分发的名称?尝试访问.name属性会产生错误,因为它不再是rv变量的属性。

import scipy.stats as stats

# Get the name of the distribution
print 'gamma :', stats.norm.name

# Create frozen distribution
rv = stats.norm()

# Get the name of the frozen distribution
print 'rv    :', rv.name
gamma : norm
rv    :

 ---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
      9 
     10 # Get the name of the frozen distribution
---> 11 print 'rv    :', rv.name

 AttributeError: 'rv_frozen' object has no attribute 'name'

1 个答案:

答案 0 :(得分:3)

冻结分发rv_frozen

冻结分发或rv_frozen class在初始化期间创建分发的实例,并将其存储在self.dist属性中。要访问原始分发的属性,请使用rv.dist.{attribute}

import scipy.stats as stats

# Get the name of the distribution
print 'gamma :', stats.norm.name

# Create frozen distribution
rv = stats.norm()

# Get the name of the frozen distribution
print 'rv    :', rv.dist.name
gamma : norm
rv    : norm