[Numpy-discussion] Setting contents of buffer for array object

Anne Archibald peridot.faceted@gmail....
Mon Feb 11 08:22:02 CST 2008


On 11/02/2008, Matthew Brett <matthew.brett@gmail.com> wrote:

> > I can also see that this could possibly be improved by using a for
> > loop to iterate over the output elements, so that there was no need to
> > duplicate the large input array, or perhaps a "blocked" iteration that
> > duplicated arrays of modest size would be better. But how can a single
> > float per data set whose median is being taken help?
>
> Sorry, you are right to call me on this very sloppy late-night
> phrasing - I only meant that it would be useful in due course to use a
> C implementation for median such as the ones you're describing, and
> that this could write the result directly into the in-place memory -
> in the same way that mean() does.  It's quite true that it's difficult
> to imagine the algorithm itself benefiting from the memory buffer.

My point was not to catch you in an error - goodness knows I make
enough of those, and not only late at night! - but to point out that
there may not really be much need for an output argument. Even with a
C code, for the median to be of much use, the output array can be at
most half the size of the input array. The extra storage space
required is not that big a concern, unlike a ufunc, and including an
output argument forces you to deal with all sorts of data conversion
issues.

On the other hand, there is something to be said for allowing the code
to destroy the input array. Perhaps *that* should be an optional
argument (defaulting to zero)?

Anne


More information about the Numpy-discussion mailing list