How to get the distribution name from a spicy.stats. frozen distribution?

岁酱吖の 提交于 2019-12-07 17:07:25

问题


Access to a Frozen Distribution's Name

When creating a frozen distribution from the scipy.stats package, how can the distribution's name be accessed once the distribution instance is frozen? Trying to access the .name attribute produces an error since it is no longer an attribute of the rv variable.

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:


The Frozen Distribution rv_frozen Class

The frozen distribution, or rv_frozen class creates an instance of the distribution during initialization and this is stored in the self.dist attribute. To access attributes of the original distribution, use 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


来源:https://stackoverflow.com/questions/37511416/how-to-get-the-distribution-name-from-a-spicy-stats-frozen-distribution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!