# How to calculate spatial correlations between two distinct maps

Dear Neurostar community,

I have come across numerous papers thats state that they conducted spatial correlations between two distinct maps, to quantify the spatial correspondence between such maps. From the articles I’ve read, there is usually a single correlation value that is provided for quantifying the correlation between two maps.

However, I am unable to find how this is done in such articles.

Can anyone provide any ideas as to how these correlations are done?

Best,
Paul

If you have two maps (`img_file1` and `img_file2`) and a brain mask (`mask_file`), then, in Python, one method to do this would be:

``````import numpy as np
# Load data as 1D (# voxels) arrays
# Calculate correlations
correlations = np.corrcoef(data1, data2)
# Grab correlation between data1 and data2 from cross-correlation matrix
corr = correlations[0, 1]
``````

Thank you tsalo for your response!

I am confused as to what is being correlated itself. How is a single correlation value being derived from two different maps? I am having trouble understanding the logic behind it all. Any insight would be great!

Let’s say your maps are both 3D (91x109x91 voxels), and your mask is the same size, with 228453 voxels that are “brain”. When you apply the masker to your images, it unravels the data and you end up with two 1D vectors of 228453 values. You then just correlate those two vectors.

Hey guys. I actually wrote a post here on that subject matter http://www.bcblab.com/BCB/Coding/Coding.html

Hope it helps
Mich