K

It's easier and faster to show than to describe:In [62]: A = np.arange(25).reshape(5,5)
In [63]: A
Out[63]:
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])
In [64]: A[:, 0]
Out[64]: array([ 0, 5, 10, 15, 20])
In [65]: A[:, 0].shape
Out[65]: (5,)
In [66]: A[:, [0]]
Out[66]:
array([[ 0],
[ 5],
[10],
[15],
[20]])
In [67]: A[:, [0]].shape
Out[67]: (5, 1)
problem np.corrcoef() I think it's in my mind when computing the collateral matrix: np.cov() And it looks like it's a calculation. np.cov() For a matrix of the single column always produces a matrix consisting of all nan:In [149]: x = np.random.randint(0, 10, (5,1))
In [150]: x
Out[150]:
array([[4],
[7],
[3],
[0],
[0]])
In [151]: np.cov(x)
c:\envs\py35\lib\site-packages\numpy\lib\function_base.py:2487: RuntimeWarning: Degrees of freedom <= 0 for slice
warnings.warn("Degrees of freedom <= 0 for slice", RuntimeWarning)
Out[151]:
array([[ nan, nan, nan, nan, nan],
[ nan, nan, nan, nan, nan],
[ nan, nan, nan, nan, nan],
[ nan, nan, nan, nan, nan],
[ nan, nan, nan, nan, nan]])
In [152]: x = np.random.randint(0, 10, (5,2))
In [153]: x
Out[153]:
array([[7, 0],
[0, 8],
[4, 2],
[1, 5],
[7, 1]])
In [154]: np.cov(x)
Out[154]:
array([[ 24.5, -28. , 7. , -14. , 21. ],
[-28. , 32. , -8. , 16. , -24. ],
[ 7. , -8. , 2. , -4. , 6. ],
[-14. , 16. , -4. , 8. , -12. ],
[ 21. , -24. , 6. , -12. , 18. ]])