# [Numpy-discussion] Counting array elements

Chris Barker Chris.Barker at noaa.gov
Tue Oct 26 09:21:08 CDT 2004

```Peter Verveer wrote:
> On Oct 25, 2004, at 11:02 PM, Tim Hochberg wrote:
>> Why the need to break backwards compatability? If one is going to
>> reimplement sum, et al so as to operate on an arbitrary set of axes
>> there's no reason one couldn't maintain the current behaviour as the
>> default.

Great idea!

> It seems to me that the behavior one would expect for a function like
> that, would be to apply the operation to the whole array. Not along an
> axis. What would you expect as a new user if you call a minimum()
> function?  A single value that is the minimum. So that is the logical
> choice for the default behavior, I would think.

nope. I'd expect it to be along an axis, by default the last one. To me,
that's what vectorization is all about. Maybe this is because of my
MATLAB (and now Numeric) background, but it makes the most sense to me
that a method either returns an array of the same rank, or "reducing"
methods return an array of rank reduced by one. Having a method return
the same rank answer, no matter the rank of the input, is weird to me.

This all depends on how you use arrays. I can see that if you tend to
use a 2-d array to store an image, that the single minimum would seem
logical, but for many other uses, each dimension has an independent meaning.

> Yes, that would be the idea anyway. The question is what should be the
> default behavior for this type of functions, something I think we should
> not decide based on the current behavior of a single existing function,
> but based on what makes the most sense. That is obviously something that
> can be discussed...

yup, but frankly, this isn't about just one function, it's really about
all the reductions: min, max, sum, etc, etc. I think the rule of thumb
is not to break backward compatibility unless there is a compelling
reason, and given that it's not clear what is most "natural" in this
case, keeping the default the same makes the most sense.

-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

Chris.Barker at noaa.gov

```