[Numpy-discussion] reduce array by computing min/max every n samples

Sebastian Haase seb.haase@gmail....
Mon Jun 21 05:15:57 CDT 2010


On Mon, Jun 21, 2010 at 10:40 AM, Neil Crighton <neilcrighton@gmail.com> wrote:
> Warren Weckesser <warren.weckesser <at> enthought.com> writes:
>
>>
>> Benjamin Root wrote:
>> > Brad, I think you are doing it the right way, but I think what is
>> > happening is that the reshape() call on the sliced array is forcing a
>> > copy to be made first.  The fact that the copy has to be made twice
>> > just worsens the issue.  I would save a copy of the reshape result (it
>> > is usually a view of the original data, unless a copy is forced), and
>> > then perform a min/max call on that with the appropriate axis.
>> >
>> > On that note, would it be a bad idea to have a function that returns a
>> > min/max tuple?
>>
>> +1.  More than once I've wanted exactly such a function.
>>
>
> I also think this would be useful. For what it's worth, IDL also has a function
> called minmax() that does this (e.g.
> http://astro.uni-tuebingen.de/software/idl/astrolib/misc/minmax.html)
>

My most favorite function I wrote many years ago using SWIG, I call
mmms(arr)
which returns a min,max,mean,std.dev  tuple.

(Of course it only works for contiguous C arrays, but it does support
most scalar dtypes via SWIG-templating)


Just my 2 cents.
- Sebastian Haase


More information about the NumPy-Discussion mailing list