I feel like this is a dumb question, but when I'm in an IPython notebook and I do help on some numpy/scipy function, like say stat.norm.rvs, it frequently says, about *args and **kargs, "see docstring of the instance object for more information". How do I see this docstring if not with help(stat.norm.rvs)?
相关问题
- scipy curve_fit cannot fit a tophat function
- Is `built-in method numpy.core._multiarray_umath.i
- What is an instance of an NSObject
- Pandas : saving Series of dictionaries to disk
- Setting elements in .data attribute to zero unplea
相关文章
- How to add clipboard support to Matplotlib figures
- Scipy.optimize.minimize method='SLSQP' ign
- Python open jp2 medical images - Scipy, glymur
- While importing auto_arima from pmdarima: ERROR :
- How to convert python list of points to numpy imag
- How to perform discrete optimization of functions
- How do I compute the variance of a column of a spa
- Why doesn't Python auto escape '\\' in
Don't feel dumb; sometimes it is hard to find the information you are looking for, especially when starting out. Moreover, much of the docstrings in
scipy.stats
are autogenerated, so they are somewhat generic, not custom-tailored. The good news is, once you undestand how to manipulate on distribution, all the others are basically the same since they share the same interface.Let's work through an example. Since you are using IPython (great!), we can also use the question mark after an object, e.g.
obj?
, to find out more about the object. This shows the docstring, likehelp(obj)
, plus other useful info such as its type, where it is defined, and (for callables) its call signature.It helps to have a picture of how things are organized.
scipy.stats
is a module:The module docstring lists many kinds of distributions.
There are two main classes --
stats.rv_continuous
andstats.rv_discrete
. Each of these distributions listed in thestats
docstring is an instance of one of these two classes.stats.norm
for example, is an instance ofstats.norm_gen
which is a subclass ofstats.rv_continuous
:Notice that
stats.norms.rvs
is an instancemethod :So when later it says
it is saying there is more information in the docstring of
stats.norm
:From this description you can see that
stats.norm.rvs(loc=10, scale=2, size=5)
will return 5 random variates with mean 10 and standard deviation 2:Alternatively,
stats.norm
is also callable -- you can pass theloc
andscale
"shape" parameters to "freeze" those parameters into the distribution. What you get back is called a "frozen distribution". For example, you can create a normal distribution with mean 10 and standard devation 2:and now call the frozen distribution's
rvs
method to obtain 5 random variates: