correlation matrix in python

后端 未结 4 724
孤街浪徒
孤街浪徒 2020-12-08 20:08

How do I calculate correlation matrix in python? I have an n-dimensional vector in which each element has 5 dimension. For example my vector looks like

[
 [0.1, .         


        
4条回答
  •  暖寄归人
    2020-12-08 20:48

    Using numpy, you could use np.corrcoef:

    In [88]: import numpy as np
    
    In [89]: np.corrcoef([[0.1, .32, .2, 0.4, 0.8], [.23, .18, .56, .61, .12], [.9, .3, .6, .5, .3], [.34, .75, .91, .19, .21]])
    Out[89]: 
    array([[ 1.        , -0.35153114, -0.74736506, -0.48917666],
           [-0.35153114,  1.        ,  0.23810227,  0.15958285],
           [-0.74736506,  0.23810227,  1.        , -0.03960706],
           [-0.48917666,  0.15958285, -0.03960706,  1.        ]])
    

提交回复
热议问题