[Numpy-discussion] unexpected behaviour of numpy.var
Hanno Klemm
klemm at phys.ethz.ch
Tue Aug 1 07:25:02 EDT 2006
Hello,
numpy.var exhibits a rather dangereous behviour, as I have just
noticed. In some cases, numpy.var calculates the variance, and in some
cases the standard deviation (=square root of variance). Is this
intended? I have to admit that I use numpy 0.9.6 at the moment. Has
this been changed in more recent versions?
Below a sample session
Python 2.4.3 (#1, May 8 2006, 18:35:42)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> a = [1,2,3,4,5]
>>> numpy.var(a)
2.5
>>> numpy.std(a)
1.5811388300841898
>>> numpy.sqrt(2.5)
1.5811388300841898
>>> a1 = numpy.array([[1],[2],[3],[4],[5]])
>>> a1
array([[1],
[2],
[3],
[4],
[5]])
>>> numpy.var(a1)
array([ 1.58113883])
>>> numpy.std(a1)
array([ 1.58113883])
>>> a =numpy.array([1,2,3,4,5])
>>> numpy.std(a)
1.5811388300841898
>>> numpy.var(a)
1.5811388300841898
>>> numpy.__version__
'0.9.6'
Hanno
--
Hanno Klemm
klemm at phys.ethz.ch
More information about the NumPy-Discussion
mailing list