[Numpy-discussion] Counting array elements
jmiller at stsci.edu
Fri Oct 22 14:19:17 CDT 2004
On Fri, 2004-10-22 at 14:17, Russell E Owen wrote:
> At 11:02 AM -0700 2004-10-22, Chris Barker wrote:
> >Stephen Walton wrote:
> >> There is a difference between the sum() Ufunc and the sum() method which
> >> is not mentioned in the documentation: the function works along an
> >> axis, while the method works on the whole array. That is, A.sum() and
> >> A.flat.sum() are equivalent regardless of the rank of A.
> >Bummer. I was hoping this was a move to a more object-oriented
> >style, rather than different functionality. Also, it's pretty
> >confusing terminology, particularly if it's not documented! Why not
> >.SumAll() or something?
sumAll() would certainly be better.
Unless there are objections, I'll rename the current sum() method to
sumAll() and re-write sum() to give a deprecation warning before calling
sumAll(). Eventually, it'll go away altogether.
I reviewed the discussion of the sum() result type from a year ago:
"[Numpy-discussion] sum and mean methods behaviour". We discussed sum()
in depth and AFIK I implemented the recommendations. The results need
to be documented.
By default, sum() now uses the maximum type of the type family of the
array, so families Bool, Integer, UnsignedInteger, Float, or Complex
result in max types Bool, Int64, UInt64, Float64, Complex64. I'm not
sure why we segregated Bool and it looks like a mistake to me now. I'm
thinking the Bool "family" should just go away and be re-classified as
UnsignedInteger. These ideas are captured by the
numerictypes.MaximumType() function which is also potentially useful for
> I agree. Numarray is already confusing enough without identically
> named functions and methods that do different things.
True enough. This'll be fixed.
> (nElements and
> size are another pet peeve, with size used in several places and
> nElements appearing exactly once. Though I am grateful to whoever
> added size as a workalike for nElements; formerly you had to know
> what kind of array you had before you knew how to find out how many
> elements it had.)
I'm not sure what you mean here. When I grepped, I got 52 hits for
nelements() in the numarray source, let alone what users have done with
it. Right now, IMHO, it's not clearly broken and there are bigger fish
More information about the Numpy-discussion