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

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.

主站蜘蛛池模板: 邢台市| 威宁| 锦屏县| 墨玉县| 青神县| 河间市| 塘沽区| 阿图什市| 禹城市| 合水县| 广州市| 屏东县| 微博| 唐河县| 蓬莱市| 黄梅县| 邓州市| 尉犁县| 岫岩| 淮阳县| 乐都县| 商丘市| 南陵县| 孟津县| 怀化市| 中方县| 宜昌市| 防城港市| 平塘县| 广南县| 秭归县| 民丰县| 儋州市| 呼玛县| 建德市| 遂昌县| 古交市| 宜兰县| 岳池县| 新巴尔虎右旗| 泰顺县|