[Numpy-discussion] sum and mean methods behaviour
Fernando Perez
fperez at colorado.edu
Tue Sep 2 12:21:07 EDT 2003
Todd Miller wrote:
> I thought about this a lot yesterday and today talked it over with
> Perry. There are several ways to fix the problem with mean() and
> sum(), and I'm hoping that you and the rest of the community will help
> sort them out.
[snip]
Just a thought: why not make the upcasting an optional parameter?
I've found that python's arguments with default values provide a very
convenient way of giving the user fine control with minimal conceptual overhead.
I'd rather write:
arr = array([255, 255], Int8)
... later
arr.sum(use_double=1) # or some similar way of tuning sum()
than
arr = array([255, 255], Int8)
... later
array(arr,typecode='d').sum()
Numarray/numpy are trying to tackle an inherently hard problem: matching the
high-level comfort of python with the low-level performance of C. This
situation is an excellent example of what I've seen described as the 'law of
leaky abstractions': in most cases where you encapsulate low level details in
a high level abstraction, there end up being situations where the details poke
through the abstraction and cause you grief. This is an inherently tricky
problem, with no easy, universal solution (that I'm aware of).
Cheers,
f.
More information about the NumPy-Discussion
mailing list