You can subscribe to this list here.
2000 |
Jan
(8) |
Feb
(49) |
Mar
(48) |
Apr
(28) |
May
(37) |
Jun
(28) |
Jul
(16) |
Aug
(16) |
Sep
(44) |
Oct
(61) |
Nov
(31) |
Dec
(24) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(56) |
Feb
(54) |
Mar
(41) |
Apr
(71) |
May
(48) |
Jun
(32) |
Jul
(53) |
Aug
(91) |
Sep
(56) |
Oct
(33) |
Nov
(81) |
Dec
(54) |
2002 |
Jan
(72) |
Feb
(37) |
Mar
(126) |
Apr
(62) |
May
(34) |
Jun
(124) |
Jul
(36) |
Aug
(34) |
Sep
(60) |
Oct
(37) |
Nov
(23) |
Dec
(104) |
2003 |
Jan
(110) |
Feb
(73) |
Mar
(42) |
Apr
(8) |
May
(76) |
Jun
(14) |
Jul
(52) |
Aug
(26) |
Sep
(108) |
Oct
(82) |
Nov
(89) |
Dec
(94) |
2004 |
Jan
(117) |
Feb
(86) |
Mar
(75) |
Apr
(55) |
May
(75) |
Jun
(160) |
Jul
(152) |
Aug
(86) |
Sep
(75) |
Oct
(134) |
Nov
(62) |
Dec
(60) |
2005 |
Jan
(187) |
Feb
(318) |
Mar
(296) |
Apr
(205) |
May
(84) |
Jun
(63) |
Jul
(122) |
Aug
(59) |
Sep
(66) |
Oct
(148) |
Nov
(120) |
Dec
(70) |
2006 |
Jan
(460) |
Feb
(683) |
Mar
(589) |
Apr
(559) |
May
(445) |
Jun
(712) |
Jul
(815) |
Aug
(663) |
Sep
(559) |
Oct
(930) |
Nov
(373) |
Dec
|
From: P G. <pgm...@gm...> - 2006-10-20 01:06:26
|
> > >class InfoArray(N.ndarray): > > > def __new__(info_arr_cls,arr,info={}): > > > info_arr_cls.info = info > > > return N.array(arr).view(info_arr_cls) > > One has to be careful of this approach. It ads *the same* information > to all arrays, i.e. Indeed. That's basically why you have to edit your __array_finalize__ . class InfoArray(N.ndarray): def __new__(info_arr_cls,arr,info={}): info_arr_cls._info = info return N.array(arr).view(info_arr_cls) def __array_finalize__(self, obj): if hasattr(obj,'info'): self.info = obj.info else: self.info = self._info return OK, so you end up w/ two attributes 'info' and '_info', the latter having the info you want, the latter playing a temporary placeholder. That looks a bit overkill, but that works pretty nice. a = InfoArray(N.array([1,2,3]),{1:1}) b = InfoArray(N.array([1,2,3]),{1:2}) assert a.info=={1:1} assert b.info=={1:2} assert (a+1).info==a.info assert (b-2).info==b.info |
From: Jay P. <pa...@gm...> - 2006-10-20 00:53:40
|
> Hi! > I try to compile numpy rc3 on Panther and get following errors. > (I start build with "python2.3 setup.py build" to be sure to use the > python shipped with OS X. I din't manage to compile Python2.5 either > yet with similar errors) > Does anynbody has an Idea? > gcc-3.3 > XCode 1.5 > November gcc updater is installed > I couldn't get numpy building with Python 2.5 on 10.3.9 (although I had different compile errors). The solution that ended up working for me was Python 2.4. There's a bug in the released version of Python 2.5 that's preventing it from working with numpy, should be fixed in the next release. You can find a .dmg for Python 2.4 here: http://pythonmac.org/packages/py24-fat/index.html Jay P. |
From: Stefan v. d. W. <st...@su...> - 2006-10-20 00:19:58
|
On Thu, Oct 19, 2006 at 09:45:02AM -0600, Travis Oliphant wrote: > Stefan van der Walt wrote: >=20 > >If I understand correctly, the following should work: > > > >import numpy as N > > > >class InfoArray(N.ndarray): > > def __new__(info_arr_cls,arr,info=3D{}): > > info_arr_cls.info =3D info > > return N.array(arr).view(info_arr_cls) One has to be careful of this approach. It ads *the same* information to all arrays, i.e. In [2]: a =3D ImageInfo(N.array([1,2,3]),{1:1}) In [3]: b =3D ImageInfo(N.array([1,2,3]),{1:2}) In [4]: a Out[4]: ImageInfo([1, 2, 3]) In [5]: b Out[5]: ImageInfo([1, 2, 3]) In [6]: a.info Out[6]: {1: 2} In [7]: b.info Out[7]: {1: 2} Regards St=E9fan |
From: Stefan v. d. W. <st...@su...> - 2006-10-19 23:10:07
|
On Thu, Oct 19, 2006 at 01:59:49PM -0700, Christopher Barker wrote: > Travis Oliphant wrote: > > Actually something as simple as > >=20 > > class InfoArray(N.ndarray): > > pass > >=20 > > will allow you to add attributes to InfoArray. >=20 > Well, sure, but how the heck do you initialize it? Looks like x =3D N.array([1,2,3]) x.view(InfoArray) works. Thanks to everyone for the useful feedback! Cheers St=E9fan |
From: Travis O. <oli...@ee...> - 2006-10-19 23:00:51
|
Christopher Barker wrote: >Travis Oliphant wrote: > > >>Actually something as simple as >> >>class InfoArray(N.ndarray): >> pass >> >>will allow you to add attributes to InfoArray. >> >> > >Well, sure, but how the heck do you initialize it? > > You use the same constructor as ndarray has. numpy.info(numpy.ndarray) If you want an array-like function that produces the array, you do array(obj).view(InfoArray) or wrap that up in your own function. There are many over-lapping ways to construct ndarray's. You can use all of these ways to construct instances of your own type by getting the ndarray and using the .view() method. -Travis |
From: Markus R. <mar...@el...> - 2006-10-19 21:56:14
|
Hi! I try to compile numpy rc3 on Panther and get following errors. (I start build with "python2.3 setup.py build" to be sure to use the python shipped with OS X. I din't manage to compile Python2.5 either yet with similar errors) Does anynbody has an Idea? gcc-3.3 XCode 1.5 November gcc updater is installed regards Markus python2.3 setup.py build ... compile options: '-Ibuild/src.darwin-7.9.0-Power_Macintosh-2.3/numpy/core/src -Inumpy/core/include -Ibuild/src.darwin-7.9.0-Power_Macintosh-2.3/numpy/core -Inumpy/core/src -Inumpy/core/include -I/System/Library/Frameworks/Python.framework/Versions/2.3/include/ python2.3 -c' gcc: numpy/core/src/multiarraymodule.c In file included from numpy/core/src/arrayobject.c:511, from numpy/core/src/multiarraymodule.c:63: numpy/core/src/arraytypes.inc.src: In function `LONGDOUBLE_scan': numpy/core/src/arraytypes.inc.src:883: warning: long double format, npy_longdouble arg (arg 3) gcc -Wl,-F. -Wl,-F. -bundle -framework Python build/temp.darwin-7.9.0-Power_Macintosh-2.3/numpy/core/src/ multiarraymodule.o -o build/lib.darwin-7.9.0-Power_Macintosh-2.3/numpy/core/multiarray.so ld: Undefined symbols: _fstatvfs referenced from Python expected to be defined in libSystem _lchown referenced from Python expected to be defined in libSystem _statvfs referenced from Python expected to be defined in libSystem ld: Undefined symbols: _fstatvfs referenced from Python expected to be defined in libSystem _lchown referenced from Python expected to be defined in libSystem _statvfs referenced from Python expected to be defined in libSystem error: Command "gcc -Wl,-F. -Wl,-F. -bundle -framework Python build/temp.darwin-7.9.0-Power_Macintosh-2.3/numpy/core/src/ multiarraymodule.o -o build/lib.darwin-7.9.0-Power_Macintosh-2.3/numpy/core/multiarray.so" failed with exit status 1 |
From: Markus R. <mro...@ma...> - 2006-10-19 21:55:47
|
Hi! I try to compile numpy rc3 on Panther and get following errors. (I start build with "python2.3 setup.py build" to be sure to use the python shipped with OS X. I din't manage to compile Python2.5 either yet with similar errors) Does anynbody has an Idea? gcc-3.3 XCode 1.5 November gcc updater is installed regards Markus python2.3 setup.py build ... compile options: '-Ibuild/src.darwin-7.9.0-Power_Macintosh-2.3/numpy/core/src -Inumpy/core/include -Ibuild/src.darwin-7.9.0-Power_Macintosh-2.3/numpy/core -Inumpy/core/src -Inumpy/core/include -I/System/Library/Frameworks/Python.framework/Versions/2.3/include/ python2.3 -c' gcc: numpy/core/src/multiarraymodule.c In file included from numpy/core/src/arrayobject.c:511, from numpy/core/src/multiarraymodule.c:63: numpy/core/src/arraytypes.inc.src: In function `LONGDOUBLE_scan': numpy/core/src/arraytypes.inc.src:883: warning: long double format, npy_longdouble arg (arg 3) gcc -Wl,-F. -Wl,-F. -bundle -framework Python build/temp.darwin-7.9.0-Power_Macintosh-2.3/numpy/core/src/ multiarraymodule.o -o build/lib.darwin-7.9.0-Power_Macintosh-2.3/numpy/core/multiarray.so ld: Undefined symbols: _fstatvfs referenced from Python expected to be defined in libSystem _lchown referenced from Python expected to be defined in libSystem _statvfs referenced from Python expected to be defined in libSystem ld: Undefined symbols: _fstatvfs referenced from Python expected to be defined in libSystem _lchown referenced from Python expected to be defined in libSystem _statvfs referenced from Python expected to be defined in libSystem error: Command "gcc -Wl,-F. -Wl,-F. -bundle -framework Python build/temp.darwin-7.9.0-Power_Macintosh-2.3/numpy/core/src/ multiarraymodule.o -o build/lib.darwin-7.9.0-Power_Macintosh-2.3/numpy/core/multiarray.so" failed with exit status 1 |
From: Tim H. <tim...@ie...> - 2006-10-19 21:35:12
|
Christopher Barker wrote: > Travis Oliphant wrote: > >> Actually something as simple as >> >> class InfoArray(N.ndarray): >> pass >> >> will allow you to add attributes to InfoArray. >> > > Well, sure, but how the heck do you initialize it? > > >>> class InfoArray(N.ndarray): > ... pass > ... > >>> InfoArray((1,2,3)) > InfoArray([[[ 6.61855173e-306, nan, 4.94708449e+173], > [ 3.32457336e-309, 1.08825491e+175, 2.12468326e-314]]]) > > InfoArray(N.array((1,2,3))) > InfoArray([[[ 2.17854722e-305, 1.90979621e-313, 1.90979621e-313], > [ 1.90979621e-313, 1.90979621e-313, 1.03977794e-312]]]) > > I, for one, would like a very easy to subclass version of ndarray, maybe > one that had a default constructor like numpy.array(). > > Back when I was working on basearray, I had an idea for this. Basically, it was to to move the ndarray constructor[1] over to basearray and make the ndarray constructor work just like array does now[2]. Thus array(args) and ndarray(args) would behave the same[2 again]. For the full power/complexity of the current ndarray constructor, you would instead use basearray(). I believe (and I did some experiments on this at one point), that this would allow straightforward inheritance from ndarray. I've been away from this for several months now, so sadly I forget many of the details. -tim [1] I know, I know, it's really __new__, but it gets used like a constructor so I'll call it one for the time being. [2] Modulo the copy arg which would disappear if I had anything to with it. |
From: Christopher B. <Chr...@no...> - 2006-10-19 21:00:21
|
Robert Kern wrote: > From the reference manual: > > http://docs.python.org/ref/augassign.html > > """An augmented assignment expression like x += 1 can be rewritten as x = x + 1 > to achieve a similar, but not exactly equal effect. In the augmented version, x > is only evaluated once. Also, when possible, the actual operation is performed > in-place, meaning that rather than creating a new object and assigning that to > the target, the old object is modified instead.""" I've always thought this was a mistake -- it is a source of weird errors and bugs. AFAIC, the augmented assignments should ONLY work with mutable objects, and ALWAYS do the operation in place. But then you couldn't write: i = 1 i += 1 Because python numbers are immutable. I think the problem here is that augmented assignment is solving two distinct problems: in place operations and nice syntax for incrementing. Oh well, it's not that big a deal, and usually the confusion causes errors that show up right away. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |
From: Christopher B. <Chr...@no...> - 2006-10-19 20:59:59
|
Travis Oliphant wrote: > Actually something as simple as > > class InfoArray(N.ndarray): > pass > > will allow you to add attributes to InfoArray. Well, sure, but how the heck do you initialize it? >>> class InfoArray(N.ndarray): ... pass ... >>> InfoArray((1,2,3)) InfoArray([[[ 6.61855173e-306, nan, 4.94708449e+173], [ 3.32457336e-309, 1.08825491e+175, 2.12468326e-314]]]) InfoArray(N.array((1,2,3))) InfoArray([[[ 2.17854722e-305, 1.90979621e-313, 1.90979621e-313], [ 1.90979621e-313, 1.90979621e-313, 1.03977794e-312]]]) I, for one, would like a very easy to subclass version of ndarray, maybe one that had a default constructor like numpy.array(). oh, and: Charles R Harris wrote: > I'd be more inclined to worry about speed. One of the drawbacks of > numarray was the time it took to create arrays. Since I often use many > small arrays, numpy was a big improvement in that area. +1 keep basic arrays simple and lean. Wasn't there one a UserArray class or something? -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |
From: Lisandro D. <da...@gm...> - 2006-10-19 20:46:53
|
On 10/19/06, Robert Kern <rob...@gm...> wrote: > Travis Oliphant wrote: > > I don't think the extra bytes for every ndarray object are worth it, > > given how easy it is to sub-class and create your own ndarray that can > > have attributes attached. What are others opinions. > > I'd say leave it off. Many uses of that feature will require custom > __array_finalize__ methods anyways. > I second Travis and Robert. --=20 Lisandro Dalc=EDn --------------- Centro Internacional de M=E9todos Computacionales en Ingenier=EDa (CIMEC) Instituto de Desarrollo Tecnol=F3gico para la Industria Qu=EDmica (INTEC) Consejo Nacional de Investigaciones Cient=EDficas y T=E9cnicas (CONICET) PTLC - G=FCemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 |
From: Charles R H. <cha...@gm...> - 2006-10-19 20:39:58
|
On 10/19/06, Tommy Grav <tg...@ma...> wrote: > > I am on a Mac OS X and are trying to install numpy/scipy/matplotlib > > ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on > Python 2.4.3 (#1, Apr 3 2006, 18:07:18) > [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import numpy > >>> numpy.__version__ > '1.1.2881' > >>> import scipy > >>> scipy.__version__ > '0.5.0.2095' > >>> import pylab > RuntimeError: module compiled against version 1000002 of C-API but this > version of numpy is 1000000 > You need a later version of numpy. The latest is 1000006 so you will probably need to also recompile both matplotlib and scipy against numpy latest. This is a recent check that Travis put in to track C-API changes. If you don't compile your own I don't know what you can do except wait. Chuck |
From: Tommy G. <tg...@ma...> - 2006-10-19 19:46:59
|
I am on a Mac OS X and are trying to install numpy/scipy/matplotlib ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on Python 2.4.3 (#1, Apr 3 2006, 18:07:18) [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> numpy.__version__ '1.1.2881' >>> import scipy >>> scipy.__version__ '0.5.0.2095' >>> import pylab RuntimeError: module compiled against version 1000002 of C-API but this version of numpy is 1000000 The import of the numpy version of the nxutils module, _nsnxutils, failed. This is is either because numpy was unavailable when matplotlib was compiled, because a dependency of _nsnxutils could not be satisfied, or because the build flag for this module was turned off in setup.py. If it appears that _nsnxutils was not built, make sure you have a working copy of numpy and then re-install matplotlib. Otherwise, the following traceback gives more details: Traceback (most recent call last): File "<stdin>", line 1, in ? File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ python2.4/site-packages/pylab.py", line 1, in ? from matplotlib.pylab import * File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ python2.4/site-packages/matplotlib/pylab.py", line 199, in ? import mlab #so I can override hist, psd, etc... File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ python2.4/site-packages/matplotlib/mlab.py", line 64, in ? import nxutils File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ python2.4/site-packages/matplotlib/nxutils.py", line 17, in ? from matplotlib._ns_nxutils import * ImportError: numpy.core.multiarray failed to import >>> Anyone know what the problem is? Cheers Tommy tg...@ma... http://homepage.mac.com/tgrav/ "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction" -- Albert Einstein |
From: Robert K. <rob...@gm...> - 2006-10-19 19:29:53
|
James K. Gruetzner wrote: > I'm using Fedora core 5, that insect-laden wonder, which includes python > 2.4.3. I'm trying to install numpy (scipy-core) and scipy (the rest). I > can't seem to get around package conflicts. I've tried two methods, one in > which numpy fails and one in which scipy fails. > > METHOD 1 (numpy fails) > Download numpy (numpy-1.0r3); untarball and install. > Test by running python and importing numpy. Looks OK, but notes "running from > numpy source directory". So, test by running python from a different > directory and importing numpy. Get the following error: > >>>> import numpy > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File "/usr/lib/python2.4/site-packages/numpy/__init__.py", line 40, in ? > import linalg > File "/usr/lib/python2.4/site-packages/numpy/linalg/__init__.py", line 4, > in ? > from linalg import * > File "/usr/lib/python2.4/site-packages/numpy/linalg/linalg.py", line 25, > in ? > from numpy.linalg import lapack_lite > ImportError: /usr/lib/python2.4/site-packages/numpy/linalg/lapack_lite.so: > undefined symbol: s_cat It looks like you linked against a FORTRAN LAPACK, but didn't manage to link the FORTRAN runtime library libg2c. Can you give us the output of your build? -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco |
From: James K. G. <jk...@sa...> - 2006-10-19 19:15:18
|
I'm using Fedora core 5, that insect-laden wonder, which includes python=20 2.4.3. I'm trying to install numpy (scipy-core) and scipy (the rest). I= =20 can't seem to get around package conflicts. I've tried two methods, one in= =20 which numpy fails and one in which scipy fails. =20 METHOD 1 (numpy fails) Download numpy (numpy-1.0r3); untarball and install. Test by running python and importing numpy. Looks OK, but notes "running f= rom=20 numpy source directory". So, test by running python from a different=20 directory and importing numpy. Get the following error: >>> import numpy Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/numpy/__init__.py", line 40, in ? import linalg File "/usr/lib/python2.4/site-packages/numpy/linalg/__init__.py", line 4,= =20 in ? from linalg import * File "/usr/lib/python2.4/site-packages/numpy/linalg/linalg.py", line 25,= =20 in ? from numpy.linalg import lapack_lite ImportError: /usr/lib/python2.4/site-packages/numpy/linalg/lapack_lite.so:= =20 undefined symbol: s_cat (The other method, where scipy fails, I'm asking for help on the scipy-user= =20 list.)) I suspect that there's a bit of out-of-sync with the packages, but am not=20 sure. Bottom line question: how do I get both installed at once? Thanks! James |
From: Alan G I. <ai...@am...> - 2006-10-19 18:08:08
|
John J. worked up short set of NumPy Indexing Examples that I think supplements what is at <URL:http://www.scipy.org/Tentative_NumPy_Tutorial#head-864862d3f2bb4c32f04260fac61eb4ef34788c4c> and <URL:http://www.scipy.org/Tentative_NumPy_Tutorial#head-0dffc419afa7d77d51062d40d2d84143db8216c2> so I made a couple edits and added them: <URL:http://www.scipy.org/Tentative_NumPy_Tutorial#head-b03fd2025aef8445d7b102c1fd0f6dc7b3521bfe> Please edit as appropriate. Thank you, Alan Isaac |
From: Tim H. <tim...@ie...> - 2006-10-19 17:08:54
|
[CHOP] OK, I've checked in changes to suppress all the warnings in the test suite. I tried to be as targeted as possible so that any regressions from the current state in terms of warnings should show up. I suspect that there may be some issues with regards to masked arrays issuing spurious warnings. I'm not a ma user, so I didn't take the time to investigate this, but someone who cares should probably look at this and consider how to resolve it. Also with regard to the recent addition of the errcall argument to errstate, it appears that if errcall is *not* specified, self.errcall will be set to None. This means that any existing error callback will be removed when entering the block (and replaced when you leave). I don't think that's the desired behavior. Instead, if errcall is not specified, I believe we should leave the value of errcall alone. Does that sound right, or am I missing something? This would result in something like: def __init__(self, **kwargs): if 'errcall' in kwargs: self.errcall = kwargs.pop('errcall') else: self.errcall = geterrcall() self.kwargs = kwargs This still allows you to set the errcall to None for the block by using: with errstate(errcall=None): # do stuff Hmm. Should that be 'errcall' or just 'call'? 'errstate(errcall...)' seems somewhat redundant. Finally, and this is a moot point anyway assuming the above rewrite, is there a reason to use: if 'errcall' in kwargs: self.errcall = kwargs.pop('errcall') else: self.errcall = geterrcall() rather than simply: self.errcall = kwargs.pop('errcall', None) ? regards, -tim |
From: David H. <dav...@gm...> - 2006-10-19 17:01:46
|
2006/10/19, Robert Kern <rob...@gm...>: > def nonreducing_reducer(reducing_func, arr, axis): > reduced = reducing_func(arr, axis=axis) > shape = list(reduced.shape) > axis = axis % len(arr.shape) > shape.insert(axis, 1) > reduced.shape = tuple(shape) > return reduced Cute ! Here is another one: 1dfunc = lambda x: atleast_1d(reducing_function(x)) apply_along_axis(1dfunc, axis, arr) Is it something people often need ? Would it be worth, (for numpy 1.1 ?), to consider complex axis arguments as a wish to preserve the rank of the array? >>> a.shape (n,m,o,p) >>> a.sum(axis=1j) (n,1,o,p) >>> a.sum(axis=1) (n,o,p) Thanks, David |
From: Charles R H. <cha...@gm...> - 2006-10-19 16:55:04
|
On 10/19/06, David Huard <dav...@gm...> wrote: > > Hi, > > Is there an elegant way to reduce an array but conserve the reduced > dimension ? > > Currently, > >>> a = random.random((10,10,10)) > >>> a.sum(1).shape > (10,10) > > but i'd like to keep (10,1,10) so I can do a/a.sum(1) directly. In [8]: a.sum(1)[:,newaxis,:].shape Out[8]: (10, 1, 10) Don't know if this is as universal as you want, but it works for this. Robert's answer is more general. Chuck |
From: Tim H. <tim...@ie...> - 2006-10-19 16:52:20
|
Robert Kern wrote: > David Huard wrote: > >> Hi, >> >> Is there an elegant way to reduce an array but conserve the reduced >> dimension ? >> >> Currently, >> >>> a = random.random((10,10,10)) >> >>> a.sum(1).shape >> (10,10) >> >> but i'd like to keep (10,1,10) so I can do a/a.sum(1) directly. >> > > def nonreducing_reducer(reducing_func, arr, axis): > reduced = reducing_func(arr, axis=axis) > shape = list(reduced.shape) > axis = axis % len(arr.shape) > shape.insert(axis, 1) > reduced.shape = tuple(shape) > return reduced > > > I think. > > Alternatively (untested): def nonreducing_reducer(reducing_func, arr, axis): return reducing_func(arr.swapaxis(0, axis), axis=0)[newaxis].swapaxis(0, axis) Adding some vertical whitespace probably wouldn't hurt for readability I suppose. -tim |
From: Tim H. <tim...@ie...> - 2006-10-19 16:49:00
|
Travis Oliphant wrote: > Tim Hochberg wrote: > > >> Travis Oliphant wrote: >> >> >> >>> Tim Hochberg wrote: >>> >>> >>> >>> >>>> Rudolph van der Merwe wrote: >>>> >>>> >>>> >>>> >>>> >>>>> I get the following error with RC3 on a RHE Linux box: >>>>> >>>>> Python 2.4.3 (#4, Mar 31 2006, 12:12:43) >>>>> [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2 >>>>> Type "help", "copyright", "credits" or "license" for more information. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> import numpy >>>>>>>> numpy.__version__ >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> '1.0rc3' >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>> On a visual studio build, I'm getting a real failure though: >>>> >>>> FAIL: Ticket #112 >>>> ---------------------------------------------------------------------- >>>> Traceback (most recent call last): >>>> File >>>> "C:\Python24\lib\site-packages\numpy\core\tests\test_regression.py", >>>> line 219, in check_longfloat_repr >>>> assert(str(a)[1:9] == str(a[0])[:8]) >>>> AssertionError >>>> >>>> The code in question is dependent on the spelling of INF(or at least the >>>> *length* of the spelling) on a given platform which is why it's failing. >>>> >>>> >>>> >>>> >>>> >>> Actually, you shouldn't be getting an INF at all. This is what the >>> test is designed to test for (so I guess it's working). The test was >>> actually written wrong and was never failing because previously keyword >>> arguments to ufuncs were ignored. >>> >>> Can you show us what 'a' is on your platform. >>> >>> >>> >> Sure: >> >> >>>>> import numpy as N >>>>> a = N.exp(N.array([1000],dtype=N.longfloat)) >>>>> >> Warning: overflow encountered in exp >> >>>>> a >>>>> >> array([1.#INF], dtype=float64) >> >> >> > O.K. We need to modify the test in case to check and see that the size > of longfloat isn't the same as double. > How about: def check_longfloat_repr(self,level=rlevel): """Ticket #112""" if N.dtype(N.longfloat) != N.dtype(N.float): a = N.exp(N.array([1000],dtype=N.longfloat)) assert(str(a)[1:9] == str(a[0])[:8]) That seems to work here. -tim |
From: Robert K. <rob...@gm...> - 2006-10-19 16:40:04
|
David Huard wrote: > Hi, > > Is there an elegant way to reduce an array but conserve the reduced > dimension ? > > Currently, > >>> a = random.random((10,10,10)) > >>> a.sum(1).shape > (10,10) > > but i'd like to keep (10,1,10) so I can do a/a.sum(1) directly. def nonreducing_reducer(reducing_func, arr, axis): reduced = reducing_func(arr, axis=axis) shape = list(reduced.shape) axis = axis % len(arr.shape) shape.insert(axis, 1) reduced.shape = tuple(shape) return reduced I think. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco |
From: David H. <dav...@gm...> - 2006-10-19 16:23:19
|
Hi, Is there an elegant way to reduce an array but conserve the reduced dimension ? Currently, >>> a = random.random((10,10,10)) >>> a.sum(1).shape (10,10) but i'd like to keep (10,1,10) so I can do a/a.sum(1) directly. Thanks, David |
From: Robert K. <rob...@gm...> - 2006-10-19 15:57:01
|
Travis Oliphant wrote: > I just learned about how to allow built-ins to have attributes assigned > to their instances. It's actually pretty easy because of Python > support for it --- but it comes at a cost. You have to add a dictionary > to the PyArrayObject structure, create that dictionary when the ndarray > is allocated, and set the tp_dictoffset in the TypeObject structure to > its location in PyArrayObject. It takes 4 lines of code with the cost of > creating a new dictionary for every ndarray. > > I don't think the extra bytes for every ndarray object are worth it, > given how easy it is to sub-class and create your own ndarray that can > have attributes attached. What are others opinions. I'd say leave it off. Many uses of that feature will require custom __array_finalize__ methods anyways. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco |
From: Charles R H. <cha...@gm...> - 2006-10-19 15:53:11
|
On 10/19/06, Travis Oliphant <oli...@ee...> wrote: > > Stefan van der Walt wrote: > > >On Wed, Oct 18, 2006 at 09:17:49PM -0400, Pierre GM wrote: > > > > > >>On Wednesday 18 October 2006 20:29, Stefan van der Walt wrote: > >> <snip> I don't think the extra bytes for every ndarray object are worth it, > given how easy it is to sub-class and create your own ndarray that can > have attributes attached. What are others opinions. I'd be more inclined to worry about speed. One of the drawbacks of numarray was the time it took to create arrays. Since I often use many small arrays, numpy was a big improvement in that area. Chuck |