|
Re: rebin (corrected): msg#00075python.numeric.general
On Mon, 30 Aug 2004, Russell E Owen wrote: > nd_image.boxcar_filter has an origin argument that *might* be for > this purpose. Unfortunately, it is not documented and my attempt to > use it as desired failed. I have no idea if this is a bug in nd_image > or a misunderstanding on my part: > >>> from numarray.nd_image import boxcar_filter > >>> b = boxcar_filter(a, (2,), origin=(1,), output_type=num.Float32) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File > "/usr/local/lib/python2.3/site-packages/numarray/nd_image/filters.py", > line 339, in boxcar_filter > output_type = output_type) > File > "/usr/local/lib/python2.3/site-packages/numarray/nd_image/filters.py", > line 280, in boxcar_filter1d > cval, origin, output_type) > RuntimeError: shift not within filter extent Seems like you got close to the answer. This gives the answer you want: >>> boxcar_filter(a, (2,), output_type=num.Float32,origin=-1) array([ 0.5, 1.5, 2.5, 3.5, 4. ], type=Float32) And so this works for rebin: >>> boxcar_filter(a, (2,), output_type=num.Float32,origin=-1)[::2].copy() array([ 0.5, 2.5, 4. ], type=Float32) But I still agree with Perry that we ought to provide a built-in rebin function. It is particularly useful for large multi-dimensional arrays where it is wasteful (in both CPU and memory) to create a full-size copy of the array before resampling it down to the desired rebinned size. I appended the .copy() so that at least the big array is not still hanging around in memory (remember that the slice creates a view rather than a copy.) Rick ------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: rebin (corrected): 00075, Russell E Owen |
|---|---|
| Next by Date: | Re: rebin (corrected): 00075, Tim Hochberg |
| Previous by Thread: | Re: rebin (corrected)i: 00075, Russell E Owen |
| Next by Thread: | Re: rebin (corrected): 00075, Tim Hochberg |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |