scipy.stats.norm.pdf的替代方案? [英] Alternative for scipy.stats.norm.pdf?

查看:106
本文介绍了scipy.stats.norm.pdf的替代方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道scipy.stats.norm.pdf()的替代方法吗?我将python网站托管在Google App Engine上,而Google不支持SciPy.

Does anyone know of an alternative for scipy.stats.norm.pdf()? I'm hosting my python site on Google App Engine and Google doesn't support SciPy.

我已经尝试过此功能,但是返回的结果与scipy相同:

I've tried this function, but that didn't return the same results as scipy:

def normpdf(x, mu, sigma):
    u = (x-mu)/abs(sigma)
    y = (1/(sqrt(2*pi)*abs(sigma)))*exp(-u*u/2)
    return y

例如:

print scipy.stats.norm.pdf(20, 20, 10)
print normpdf(20, 20, 10)

print scipy.stats.norm.pdf(15, 20, 10)
print normpdf(15, 20, 10)

print scipy.stats.norm.pdf(10, 20, 10)
print normpdf(10, 20, 10)

返回以下值:

0.0398942280401
0.0398942280401

0.0352065326764
0.0146762663174

0.0241970724519
0.0146762663174

推荐答案

您被python的整数除法所欺骗!这是一些工作代码:

You got tricked by pythons integer division arithmetics! Here is some working code:

from __future__ import division

import scipy.stats
from numpy import *

def normpdf(x, mu, sigma):
    u = (x-mu)/abs(sigma)
    y = (1/(sqrt(2*pi)*abs(sigma)))*exp(-u*u/2)
    return y


print scipy.stats.norm.pdf(20, 20, 10)
print normpdf(20, 20, 10)

print scipy.stats.norm.pdf(15, 20, 10)
print normpdf(15, 20, 10)

print scipy.stats.norm.pdf(10, 20, 10)
print normpdf(10, 20, 10)

注意第一行!否则,您可以将每个输入变量转换为浮点数,例如乘以 1.

Note the first line! Otherwise, you could convert each input variable to a float, e.g. by multiplying by 1.

这篇关于scipy.stats.norm.pdf的替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆