[Numpy-discussion] ndarray methods vs numpy module functions

Stéfan van der Walt stefan at sun.ac.za
Tue Jun 24 04:39:17 EDT 2008


Hi Bob

2008/6/24 Bob Dowling <rjd4 at cam.ac.uk>:
> I would make a plea for consistency, to start with.
>
> Those of us who write in an OO style are required to switch backwards
> and forwards between OO and not-OO, or to abandon OO altogether in our
> NumPy code.  Neither is an attractive option.

There are an infinite number of operations to be performed on arrays,
so the question becomes: which of those belong as members of the
class?  In my opinion, none do; we have them simply for backward
compatibility.

In general, my feeling (not the status quo) is to:

a) Use array methods for in-place operations and operations pertaining
specifically to ndarrays.  This would include `sort`, but not `sum` or
`dump`.
b) Use numpy functions for operations that copy the object, or do
calculations that yield new objects.

Even if you subscribe to such a rule, having x.sum() at hand is
convenient, so many people use it.  There's bound to be a big outcry
if we try to remove them now.  I'm not even sure most people would
agree with these guidelines.

Regards
Stéfan



More information about the NumPy-Discussion mailing list