从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'
答案 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