[pymvpa] correlation between 2 matrices

Christopher J Markiewicz effigies at bu.edu
Fri Oct 28 20:07:47 UTC 2016


Sounds like you just want the correlation coefficient of the two
matrices, unraveled?

import numpy as np

def similarity(matA, matB):
    coeffs = np.corrcoef(matA.reshape(-1), matB.reshape(-1))
    return coeffs[0, 1]


Or did you want a coefficient for each time point?

Assuming rows are time points:

def similarity(matA, matB):
    nrows = matA.shape[0]
    coeffs = np.corrcoef(matA, matB)
    topright = coeffs[:nrows,nrows:]
    return topright.diagonal()


If you're starting from PyMVPA datasets, you can use:

similarity(dsA.samples, dsB.samples)


On 10/28/2016 03:44 PM, David Soto wrote:
> hi, 
> 
> I wonder whether PyMVPA can compute a similarity index (correlation)
> between two 2D matrices, each comprised of 12 seconds & 300 voxels?
> 
> thanks!
> david
> 
> 
> _______________________________________________
> Pkg-ExpPsy-PyMVPA mailing list
> Pkg-ExpPsy-PyMVPA at lists.alioth.debian.org
> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-exppsy-pymvpa
> 


-- 
Christopher J Markiewicz
Ph.D. Candidate, Quantitative Neuroscience Laboratory
Boston University



More information about the Pkg-ExpPsy-PyMVPA mailing list