[SciPy-Dev] Better __repr__ for scipy.stats distributions

Stefan van der Walt stefanv at berkeley.edu
Tue Jan 29 16:30:03 EST 2019


On Wed, 30 Jan 2019 07:54:17 +1100, Andrew Nelson wrote:
> ... would like to propose that the __repr__ of
> these classes be improved to a point where the repr can be used to
> reproduce the distribution.
> 
> e.g instead of:
> 
> >>> from scipy.stats import norm
> >>> print(repr(norm(0, 1)))
> <scipy.stats._distn_infrastructure.rv_frozen object at 0x1a17c8f898>
> 
> one would get:
> norm(0, 1)

That seems like a very reasonable request.  `scikit-learn` does
something similar:

In [6]: br = linear_model.BayesianRidge()                                                

In [7]: br

Out[7]: 
BayesianRidge(alpha_1=1e-06, alpha_2=1e-06, compute_score=False, copy_X=True,
       fit_intercept=True, lambda_1=1e-06, lambda_2=1e-06, n_iter=300,
       normalize=False, tol=0.001, verbose=False)

The only concern I can see may be about the internal state of the RNG
that keeps changing after values are generated.

Stéfan


More information about the SciPy-Dev mailing list