scipy stats.rv_continuous() | Python (original) (raw)

Last Updated : 20 Mar, 2019

**scipy.stats.rv_continuous()** is a continuous random variable class which is meant for sub-classing. It is a base class for constructing specific distribution from continuous random variables. This class can't directly be used as a distribution.

Parameters : moment : [int] moment calculation to use: 0 for pdf, 1 for ppf. Default = 1a : [float] Lower bound for distribution. Default is -ve infinity. b : [float] Upper bound for distribution. Default is +ve infinity.xtol : [float] tolerance for fixed point calculation for ppfname : [str] Name of the instance. Used to construct the default e.g. for distributionsbadvalue : [object] Default is np.nan. Value in a result arrays that indicates a value that for which some argument restriction is violated. logname : [str] Used as part of theFirst line of the docstring.extradoc : [str] Used as the last part of the docstringshapes : [str] Shape of the distribution.Return : Continuous Random Variable Distribution.

Code #1 : Using "rv_continuous class".

Python3 1== `

def sample(self, size = 1, random_state = None):

    """
    Return a sample from PDF - Probability Distribution Function.
    calling - rv_continuous class.

    """
    
    return self._rv.rvs(size = size, random_state = random_state) 

`

Code #2 : Creating Gaussian Distribution from rv_continuous.

Python3 1== `

from scipy.stats import rv_continuous import numpy as np

class gaussian_gen(rv_continuous): '''Gaussian distribution''' def _pdf(self, x): return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)

gaussian = gaussian_gen(name = 'gaussian')

x = 2.0 gaussian._pdf(x)

`

Output :

0.05399096651318806