Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I was trying one Dataquest exercise and I figured out that the variance I am getting is different for the two packages..

e.g for [1,2,3,4]

from statistics import variance 

import numpy as np 

print(np.var([1,2,3,4])) 

print(variance([1,2,3,4])) 

//1.25 

//1.6666666666666667

The expected answer to the exercise is calculated with np.var()

1 Answer

0 votes
by (106k points)

You can use the below-mentioned code to understand the difference:-

print(np.var([1,2,3,4],ddof=1)) 

1.66666666667

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
asked Oct 8, 2019 in Python by Sammy (47.6k points)
+3 votes
2 answers

Browse Categories

...