本文介绍了相当于Matlab Corr2的Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道matlab函数corr2的python等效项是什么,它给出2个矩阵之间的相关系数,仅返回一个值.

I want to know what is the python equivalent of the matlab function corr2 that gives the correlation coefficient between 2 matrices, return only one value.

http://www.mathworks.com/help/images/ref/corr2.html

我只发现python中的等效项是scipy.signal.correlate2d,但这会返回一个数组.

I only found that the equivalent in python is scipy.signal.correlate2d but this returns an array.

谢谢.

推荐答案

也许可以为您提供帮助

def mean2(x):
    y = np.sum(x) / np.size(x);
    return y

def corr2(a,b):
    a = a - mean2(a)
    b = b - mean2(b)

    r = (a*b).sum() / math.sqrt((a*a).sum() * (b*b).sum());
    return r

这篇关于相当于Matlab Corr2的Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 06:39