How to get the distribution name from a spicy.stat

2019-05-23 08:46发布

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条回答
干净又极端
2楼-- · 2019-05-23 09:08

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
查看更多
登录 后发表回答