0

Consider the following array:

x=[80    55   304   115     5    24    72]

When I use np.var(x)=8508.8164, however, Matlab's var(x) = 9.9270e+03. How can this be? Is there a different function I should be using in Python?

user3600497
  • 1,621
  • 1
  • 18
  • 22
  • 3
    I'm confident it stems from the default degrees of freedom being 0 for NumPy, as covered in [this question](http://stackoverflow.com/questions/27600207/why-does-numpy-std-give-a-different-result-to-matlab-std) about `std()`. – TroyHaskin Aug 11 '15 at 17:06
  • 2
    @TroyHaskin - Correct. I've marked that post as a duplicate. Thanks for providing a link! – rayryeng Aug 11 '15 at 17:09
  • Thanks, Ill take a look at the other question. – user3600497 Aug 11 '15 at 17:10
  • @user3600497 - As a bonus, I've verified that providing `ddof=1` to `numpy.var` gives you the same result as `var()` in MATLAB. MATLAB: `x = [80 55 304 115 5 24 72]; format long g; var(x) --> 9926.95238095238`. Python: `import numpy as np; x = np.array([80,55,304,115,5,24,72]); np.var(x, ddof=1) --> 9926.9523809523816`. – rayryeng Aug 11 '15 at 17:14
  • 1
    Yes, I have verified that too. Thanks guys. – user3600497 Aug 11 '15 at 17:16

0 Answers0