官术网_书友最值得收藏!

Using Python to compute standard deviation and variance

Now, NumPy also makes it incredibly easy to compute the standard deviation and variance. If you want to compute the actual standard deviation of this dataset that we generated, you just call the std function right on the dataset itself. So, when NumPy creates the list, it's not just a normal Python list, it actually has some extra stuff tacked onto it so you can call functions on it, like std for standard deviation. Let's do that now:

incomes.std() 

This gives us something like the following output (remember that we used random data, so your figures won't be exactly the same as mine):

20.024538249134373 

When we execute that, we get a number pretty close to 20, because that's what we specified when we created our random data. We wanted a standard deviation of 20. Sure enough, 20.02, pretty close.

The variance is just a matter of calling var.

incomes.var() 

This gives me the following:

400.98213209104557 

It comes out to pretty close to 400, which is 202. Right, so the world makes sense! Standard deviation is just the square root of the variance, or you could say that the variance is the standard deviation squared. Sure enough, that works out, so the world works the way it should.

主站蜘蛛池模板: 毕节市| 南郑县| 南漳县| 凌云县| 淄博市| 鲜城| 巍山| 武宣县| 朔州市| 武鸣县| 丰都县| 巴林左旗| 左云县| 太康县| 年辖:市辖区| 北碚区| 旬邑县| 虎林市| 罗田县| 聂荣县| 盐源县| 疏勒县| 丁青县| 建水县| 澜沧| 周至县| 砚山县| 临沧市| 方城县| 五莲县| 新乡市| 桂阳县| 内乡县| 余江县| 铜山县| 洞头县| 宿迁市| 麻阳| 大关县| 敦化市| 千阳县|