[Numpy-discussion] What should be the return type of average?

Charles R Harris charlesr.harris@gmail....
Sun Mar 16 06:59:12 CDT 2008


On Sun, Mar 16, 2008 at 4:11 AM, Sebastian Haase <haase@msg.ucsf.edu> wrote:

> On Sun, Mar 16, 2008 at 1:08 AM, Charles R Harris
> <charlesr.harris@gmail.com> wrote:
> > Hi,
> >
> > I want to fix up the average function. I note that the return dtype is
> not
> > specified, nor is the precision of the accumulator. Both of these can be
> > specified for the mean method and I wonder what should be the case for
> > average. Or should we just use double precision? That would seem
> appropriate
> > to me most of the time, but wouldn't match what happens with mean and
> would
> > lose precision in the case of extended precision doubles. There is also
> no
> > out keyword, do we want one?
> >
>
> Hi,
> I'm starting to forget... but faintly I'm remembering that there might
> have been some extended discussion about this on this list.
> We work with large multi-dimensional image data, so if, for example, I
> have n (small) 50x512x512 3D-images that I want to average into one
> 50x512x512 image, the most memory I can afford is single precession
> float32. (Also the original dynamic range is 16bit at best anyway)
>
> I was just checking my archives:
> http://projects.scipy.org/scipy/numpy/ticket/465#comment:2 (by
> oliphant) actually already says this.


What I ended up with is double for integer input types and preservation of
float types. Thus float32 will be preserved but int8 will return double.
These are the same rules one gets with A + 0.0, which is how I did it. That
isn't really the most space efficient, however, as in your case a copy of
the data cube will be made.

As to accumulator type and an out variable, there are already so many
parameters in the function that I have become loath to add more at this
point, but it would be easy to specify an accumulator type and specifying an
out variable shouldn't be much worse.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080316/2a352445/attachment.html 


More information about the Numpy-discussion mailing list