Your message dated Tue, 9 Dec 2008 09:42:23 +0100 with message-id <[EMAIL PROTECTED]> and subject line Re: Bug#467095: python-numpy: numpy.average() returns the wrong result with weights. has caused the Debian Bug report #467095, regarding python-numpy: numpy.average() returns the wrong result with weights. to be marked as done.
This means that you claim that the problem has been dealt with. If this is not the case it is now your responsibility to reopen the Bug report if necessary, and/or fix the problem forthwith. (NB: If you are a system administrator and have no idea what this message is talking about, this may indicate a serious mail system misconfiguration somewhere. Please contact [EMAIL PROTECTED] immediately.) -- 467095: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=467095 Debian Bug Tracking System Contact [EMAIL PROTECTED] with problems
--- Begin Message ---Package: python-numpy Version: 1:1.0.4-5 Severity: normal >>> x = numpy.array([[1,2,3,4,5,6,2],[2,2,3,4,5,6,3]]).transpose() >>> wt = numpy.array([1,1,1,1,1,1,2]) >>> numpy.average(x, weights=wt, axis=0) array([[[[[[ 1., 2.], [ 2., 2.], [ 3., 3.], [ 4., 4.], [ 5., 5.], [ 6., 6.], [ 2., 3.]]]]]]) So, the weighted average of a 2-dimentional array is a 6-dimensional array? Or, slightly better: >>> x = numpy.array([range(100),range(100)]).transpose() >>> wt = numpy.array(range(100)) >>> numpy.average(x, weights=wt, axis=0) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/local/lib/python2.4/site-packages/numpy-1.0.4-py2.4-linux-i686.egg/numpy/lib/function_base.py", line 379, in average w1 = eval("w["+repr(tuple(r))+"]*ones(ash, float)") File "<string>", line 0, in ? IndexError: too many indices >>> The problem seems to be in .../numpy/lib/function_base.py right here: if wsh == (): wsh = (1,) if wsh == ash: n = add.reduce(a*w, axis) d = add.reduce(w, axis) elif wsh == (ash[axis],): # ni = len(ash) #CORRECT! ni = ash[axis] # WRONG! r = [newaxis]*ni r[axis] = slice(None, None, 1) w1 = eval("w["+repr(tuple(r))+"]*ones(ash, float)") n = add.reduce(a*w1, axis) d = add.reduce(w1, axis) else: raise ValueError, 'averaging weights have wrong shape' The existing code generates an array whose dimensionality is equal to shape[axis], so it you have a 2-dimensional array with a shape of (1000,3), it will try to generate a 1000-dimensional array on the output. And, Geez! Calling eval() in code that is supposed to be fast? Yikes! (But that's a separate issue...) -- System Information: Debian Release: lenny/sid APT prefers testing APT policy: (500, 'testing') Architecture: i386 (i686) Kernel: Linux 2.6.22-3-686 (SMP w/1 CPU core) Locale: LANG=en_GB, LC_CTYPE=en_GB (charmap=ISO-8859-1) Shell: /bin/sh linked to /bin/bash Versions of packages python-numpy depends on: ii atlas3-base [liblapack 3.6.0-20.6 Automatically Tuned Linear Algebra ii atlas3-sse2 [liblapack 3.6.0-20.6 Automatically Tuned Linear Algebra ii lapack3 [liblapack.so. 3.0.20000531a-6.1 library of linear algebra routines ii libc6 2.7-6 GNU C Library: Shared libraries ii libg2c0 1:3.4.6-6 Runtime library for GNU Fortran 77 ii libgcc1 1:4.3-20080202-1 GCC support library ii python 2.4.4-6 An interactive high-level object-o ii python-support 0.7.6 automated rebuilding support for p ii refblas3 [libblas.so.3 1.2-8 Basic Linear Algebra Subroutines 3 python-numpy recommends no packages. -- no debconf information
--- End Message ---
--- Begin Message ---On Sat, Feb 23, 2008 at 1:50 AM, Ondrej Certik <[EMAIL PROTECTED]> wrote: > On Sat, Feb 23, 2008 at 1:08 AM, Greg Kochanski <[EMAIL PROTECTED]> wrote: >> Package: python-numpy >> Version: 1:1.0.4-5 >> Severity: normal >> >> >> >>> x = numpy.array([[1,2,3,4,5,6,2],[2,2,3,4,5,6,3]]).transpose() >> >>> wt = numpy.array([1,1,1,1,1,1,2]) >> >>> numpy.average(x, weights=wt, axis=0) >> array([[[[[[ 1., 2.], >> [ 2., 2.], >> [ 3., 3.], >> [ 4., 4.], >> [ 5., 5.], >> [ 6., 6.], >> [ 2., 3.]]]]]]) >> >> So, the weighted average of a 2-dimentional array is a 6-dimensional >> array? >> >> Or, slightly better: >> >>> x = numpy.array([range(100),range(100)]).transpose() >> >>> wt = numpy.array(range(100)) >> >>> numpy.average(x, weights=wt, axis=0) >> Traceback (most recent call last): >> File "<stdin>", line 1, in ? >> File >> "/usr/local/lib/python2.4/site-packages/numpy-1.0.4-py2.4-linux-i686.egg/numpy/lib/function_base.py", >> line 379, in average >> w1 = eval("w["+repr(tuple(r))+"]*ones(ash, float)") >> File "<string>", line 0, in ? >> IndexError: too many indices >> >>> >> >> >> The problem seems to be in .../numpy/lib/function_base.py >> right here: >> >> if wsh == (): >> wsh = (1,) >> if wsh == ash: >> n = add.reduce(a*w, axis) >> d = add.reduce(w, axis) >> elif wsh == (ash[axis],): >> # ni = len(ash) #CORRECT! >> ni = ash[axis] # WRONG! >> r = [newaxis]*ni >> r[axis] = slice(None, None, 1) >> w1 = eval("w["+repr(tuple(r))+"]*ones(ash, float)") >> n = add.reduce(a*w1, axis) >> d = add.reduce(w1, axis) >> else: >> raise ValueError, 'averaging weights have wrong shape' >> >> >> The existing code generates an array whose dimensionality is >> equal to shape[axis], so it you have a 2-dimensional array >> with a shape of (1000,3), it will try to generate a 1000-dimensional >> array on the output. > > Thanks for the bug report and a fix. Reported upstream: > > http://projects.scipy.org/pipermail/numpy-discussion/2008-February/031562.html > >> And, Geez! Calling eval() in code that is supposed to be fast? >> Yikes! (But that's a separate issue...) > > Please report the issue. :) Even better - offer upstream a fix > directly on their mailinglist. Both problems seem to be fixed now, see the above link, or this session: In [2]: import numpy In [3]: x = numpy.array([[1,2,3,4,5,6,2],[2,2,3,4,5,6,3]]).transpose() In [4]: wt = numpy.array([1,1,1,1,1,1,2]) In [5]: numpy.average(x, weights=wt, axis=0) Out[5]: array([ 3.125, 3.5 ]) In [6]: x = numpy.array([range(100),range(100)]).transpose() In [7]: wt = numpy.array(range(100)) In [8]: numpy.average(x, weights=wt, axis=0) Out[8]: array([ 66.33333333, 66.33333333]) So I am closing the bug. Please reopen if you still find some problems. Ondrej
--- End Message ---
_______________________________________________ Python-modules-team mailing list [email protected] http://lists.alioth.debian.org/mailman/listinfo/python-modules-team

