The Python Oracle

Numpy Covariance Matrix numpy.cov

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Secret Catacombs

--

Chapters
00:00 Numpy Covariance Matrix Numpy.Cov
00:46 Accepted Answer Score 17
01:01 Answer 2 Score 1
01:13 Thank you

--

Full question
https://stackoverflow.com/questions/4317...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #matlab #numpy #sympy #covariance

#avk47



ACCEPTED ANSWER

Score 17


Amazingly, the documentation might tell you. You should pass rowvar=False to indicate that columns represent variables.

>>> data.shape
(768, 8)
>>> numpy.cov(data, rowvar=False).shape
(8, 8)



ANSWER 2

Score 1


as per default, each row is observation, each column is feature, which is swaped in numpi per definition, so all you need to do is transpose, where R is matrix

np.cov(R.T) 

or

np.cov(R, rowvar = False)