numpy.cov() and numpy.var() default bias are inconsistent (numpy 1.9.2)
See original GitHub issuecov() uses a bias of 1 by default. var() uses a bias of 0 by default.
Such that
import numpy as np
x = np.random.rand(100)
if np.isclose(np.cov([x,x])[0,0], np.var(x)):
print("Consistent by default.")
if np.isclose(np.cov([x,x],ddof=0)[0,0], np.var(x,ddof=0))
print("Consistent.")
will only print the second line.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Allen Downey on Twitter: "I ran into a NumPy gotcha today: np ...
numpy.cov() and numpy.var() default bias are inconsistent (numpy 1.9.2) · Issue #5835 · numpy/numpy. cov() uses a bias of 1 by default.
Read more >numpy.cov — NumPy v1.24 Manual
If rowvar is True (default), then each row represents a variable, with observations in the columns. Otherwise, the relationship is transposed: each column ......
Read more >Var(x) and cov(x, x) don't give the same result in numpy
You must use z=cov(x,bias=1) in order to normalize by N ,because var is also norm by N (according to this.
Read more >Release Notes — NumPy v1.14 Manual
In the future, calling .item() on arrays or scalars of np.void datatype will return a bytes object instead of a buffer or int...
Read more >Release Notes — NumPy v1.10 Manual
There was inconsistent behavior between x.ravel() and np.ravel(x), ... If this variable is set to 1, then numpy will consider more arrays to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@rgommers Yeah, “never break valid code” is a pretty good rule.
How about a warning if you call
cov
withoutbias
orddof
, and then never change the behavior?That does seem like a reasonable thing to do. Better than deprecating
cov
. Having to addddof=0/1
is a slight annoyance but makes the code more understandable, so I like the idea.