Joh*_*nak 6 python numpy matrix correlation
A 有一个n x m矩阵,其中 rowi表示变量的时间序列V_i。我想计算n x n相关矩阵M,其中M_{i,j}包含的相关系数(皮尔森r之间)V_i和V_j。
但是,当我在 numpy 中尝试以下操作时:
numpy.corrcoef(numpy.matrix('5 6 7; 1 1 1'))
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
array([[ 1., nan],
[ nan, nan]])
Run Code Online (Sandbox Code Playgroud)
似乎numpy.corrcoef不喜欢单位向量,因为如果我将第二行更改为 ,则会7 6 5得到预期的结果:
array([[ 1., -1.],
[ -1., 1.]])
Run Code Online (Sandbox Code Playgroud)
这种行为的原因是numpy.corrcoef什么?