I want to compute the correlation between the two arrays a
and b
; the shape of a
and b
is (10, 2)
. I expect a correlation matrix with shape (10, 10)
with values in the range [-1, 1]
; a correlation value for every pair.
>>> a
array([[-1.22674504, 0.08136256],
[ 1.95456381, -1.31209914],
[ 0.29199221, 0.00573356],
[ 0.66700798, -0.68239164],
[-1.03723395, -0.15456914],
[-0.52541249, -0.21180142],
[-0.94584861, -0.81954194],
[ 1.11044632, 2.02689438],
[-0.12003807, 0.00595059],
[-0.16873215, 1.06046219]])
>>> b
array([[-0.06960341, 0.01320213],
[ 0.1108986 , -0.21290515],
[ 0.01656714, 0.00093034],
[ 0.03784489, -0.11072692],
[-0.05885088, -0.02508085],
[-0.029811 , -0.03436753],
[-0.05366583, -0.13298134],
[ 0.06300482, 0.32888998],
[-0.00681075, 0.00096556],
[-0.00957357, 0.17207378]])
I use numpy.corrcoef(a, b)
and get a (20, 20)
matrix, instead of (10, 10)
.
>>> numpy.corrcoef(a, b)
array([[ 1., -1., -1., -1., 1., 1., 1., 1., 1., 1., 1., -1., -1.,
-1., 1., -1., -1., 1., 1., 1.],
[-1., 1., 1., 1., -1., -1., -1., -1., -1., -1., -1., 1., 1.,
1., -1., 1., 1., -1., -1., -1.],
[-1., 1., 1., 1., -1., -1., -1., -1., -1., -1., -1., 1., 1.,
1., -1., 1., 1., -1., -1., -1.],
[-1., 1., 1., 1., -1., -1., -1., -1., -1., -1., -1., 1., 1.,
1., -1., 1., 1., -1., -1., -1.],
[ 1., -1., -1., -1., 1., 1., 1., 1., 1., 1., 1., -1., -1.,
-1., 1., -1., -1., 1., 1., 1.],
[ 1., -1., -1., -1., 1., 1., 1., 1., 1., 1., 1., -1., -1.,
-1., 1., -1., -1., 1., 1., 1.],
[ 1., -1., -1., -1., 1., 1., 1., 1., 1., 1., 1., -1., -1.,
-1., 1., -1., -1., 1., 1., 1.],
[ 1., -1., -1., -1., 1., 1., 1., 1., 1., 1., 1., -1., -1.,
-1., 1., -1., -1., 1., 1., 1.],
[ 1., -1., -1., -1., 1., 1., 1., 1., 1., 1., 1., -1., -1.,
-1., 1., -1., -1., 1., 1., 1.],
[ 1., -1., -1., -1., 1., 1., 1., 1., 1., 1., 1., -1., -1.,
-1., 1., -1., -1., 1., 1., 1.],
[ 1., -1., -1., -1., 1., 1., 1., 1., 1., 1., 1., -1., -1.,
-1., 1., -1., -1., 1., 1., 1.],
[-1., 1., 1., 1., -1., -1., -1., -1., -1., -1., -1., 1., 1.,
1., -1., 1., 1., -1., -1., -1.],
[-1., 1., 1., 1., -1., -1., -1., -1., -1., -1., -1., 1., 1.,
1., -1., 1., 1., -1., -1., -1.],
[-1., 1., 1., 1., -1., -1., -1., -1., -1., -1., -1., 1., 1.,
1., -1., 1., 1., -1., -1., -1.],
[ 1., -1., -1., -1., 1., 1., 1., 1., 1., 1., 1., -1., -1.,
-1., 1., -1., -1., 1., 1., 1.],
[-1., 1., 1., 1., -1., -1., -1., -1., -1., -1., -1., 1., 1.,
1., -1., 1., 1., -1., -1., -1.],
[-1., 1., 1., 1., -1., -1., -1., -1., -1., -1., -1., 1., 1.,
1., -1., 1., 1., -1., -1., -1.],
[ 1., -1., -1., -1., 1., 1., 1., 1., 1., 1., 1., -1., -1.,
-1., 1., -1., -1., 1., 1., 1.],
[ 1., -1., -1., -1., 1., 1., 1., 1., 1., 1., 1., -1., -1.,
-1., 1., -1., -1., 1., 1., 1.],
[ 1., -1., -1., -1., 1., 1., 1., 1., 1., 1., 1., -1., -1.,
-1., 1., -1., -1., 1., 1., 1.]])
One row is one observation with two values, how can I tell Python that it is 2-dimensional to compute the correlation? Why is every value exactly -1
or 1
?