[Numpy-discussion] unexpected behaviour of numpy.var

Sasha ndarray at mac.com
Tue Aug 1 11:07:33 CDT 2006


I cannot reproduce your results, but I wonder if the following is right:

>>> a = array([1,2,3,4,5])
>>> var(a[newaxis,:])
array([ 0.,  0.,  0.,  0.,  0.])
>>> a[newaxis,:].var()
2.0
>>> a[newaxis,:].var(axis=0)
array([ 0.,  0.,  0.,  0.,  0.])

Are method and function supposed to have different defaults?  It looks
like the method defaults to variance over all axes while the function
defaults to axis=0.

>>> __version__
'1.0b2.dev2192'



On 8/1/06, Hanno Klemm <klemm at phys.ethz.ch> wrote:
>
> 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
>
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>




More information about the Numpy-discussion mailing list