R语言的digamma、gamma、dgamma与norm函数对应python函数包的问题

R语言代码转为python代码

  1. R语言的digamma、gamma函数:用作计算伽马函数的对数导数

    1. python中替代函数:from scipy.special import digamma, gamma

      # 示例 示例为digamma,gamma函数类似
      digamma(alpha)  # R写法
      # python直接调对应函数,写法相同
      digamma(alpha)  # python写法 
      
  2. R语言的dgamma函数,用作计算伽马函数的概率参数

    1. python中替代函数:from scipy.stats import gamma

      # 示例
      dgamma(c(1,2,3),shape=2.1, rate=3.2)  # R代码写法
      # shape 等于python中的a  rate是scale的倒数
      al = gamma.pdf([1, 2, 3], a=2.1, scale=(1/3.2))  # 对应python写法
      
  3. R语言的dnorm函数,用作计算正态的概率函数

    1. python中替代函数:from scipy.stats import norm

      # 示例
      dnorm(c(1,2,3), mean = 1.8, sd = 3.5)  # R写法
      # mean对应python中的local sd对应scale
      norm.pdf([1, 2, 3], loc=1.8, scale=3.5)  # python写法
      

你可能感兴趣的:(深度学习,R语言,python,r语言,python,深度学习)