Search code examples
scipyimporterrorpython-3.9scipy.stats

Scipy.stats allows import of `norm` but not `norm_gen`


I want to import the "class factory" of the normal distribution in Scipy to tweak it but I get an import error when doing so:

In [5]: from scipy.stats import norm                                                                                                                                                                                                                                     

In [6]: from scipy.stats import norm_gen                                                                                                                                                                                                                                 
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-6-033da3de46bb> in <module>
----> 1 from scipy.stats import norm_gen

ImportError: cannot import name 'norm_gen' from 'scipy.stats' (/usr/local/anaconda3/lib/python3.7/site-packages/scipy/stats/__init__.py)

I cannot make sense of this ImportError. How can I work around it? Except for pasting the code from norm_gen locally.


Solution

  • Try importing it from scipy.stats.distrubutions. This is however a bit of a hack and is not guaranteed to be forward-compatible . You might want to reconsider your code and your reasons to inherit from _gen classes : those are an implementation detail. Inheriting from rv_continuous is supported though.