matlab corr2的Python等价物

2024-04-20 11:27:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道matlab函数corr2的python等价物是什么,corr2给出了两个矩阵之间的相关系数,只返回一个值。在

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

我只发现python中的等价物是scipy.signal.correlate2d但这会返回一个数组。在

谢谢。在


Tags: 函数comrefhttpsignalhtmlwwwhelp
2条回答
import numpy
print numpy.corrcoef(x,y)

其中x和y可以是一维或二维数组。在

看看文档here。在

也许这对你有帮助

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

相关问题 更多 >