利用Python的pip命令安装nump
》将python安装目录中的script的目录导入到环境变量path中
》在windows的DOS窗口执行:pip
》》将出现pip的相关信息
》在Windows中的DOS界面中执行:pip install nump
》》系统会自动下载nump包,并且完成相应的安装
》》因为,我已经安装过啦,所以不会出现下载的进度条(注:下载比较缓慢)
》前提:你已经安装了python3.5.2
》》Python3.5.2下载链接:python官网
》测试案例:
# import the necessary packages
import numpy as np
def chi2_distance(histA, histB, eps = 1e-10):
# compute the chi-squared distance
d = 0.5 * np.sum([((a - b) ** 2) / (a + b + eps)
for (a, b) in zip(histA, histB)])
Sum = 0;
for (a,b) in zip(histA, histB):
E = ((a - b) ** 2) / (a + b + eps)
Sum += E
print Sum/2
# return the chi-squared distance
return d
d = chi2_distance([0,1,2,3,4],[4,3,2,1,0])
# print d
相关文章