📜  scipy stats.rv_continuous() | Python

📅  最后修改于: 2022-05-13 01:54:45.259000             🧑  作者: Mango

scipy stats.rv_continuous() | Python

scipy.stats.rv_continuous()是一个连续随机变量类,用于子分类。它是从连续随机变量构造特定分布的基类。此类不能直接用作分发。

代码 #1:使用“rv_continuous 类”。

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) 

代码 #2:从 rv_continuous 创建高斯分布。

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)

输出 :

0.05399096651318806