[Numpy-discussion] ndarray methods vs numpy module functions

Anne Archibald peridot.faceted@gmail....
Tue Jun 24 03:36:32 CDT 2008


2008/6/24 Bob Dowling <rjd4@cam.ac.uk>:
>> There is not supposed to be a one-to-one correspondence between the
>> functions in numpy and the methods on an ndarray. There is some
>> duplication between the two, but that is not a reason to make more
>> duplication.
>
> 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.
>
> The reason I tripped over this is that I am currently writing a course
> which introduces students to NumPy.  I am going to be asked this
> question from the audience.  As yet I don't have any answer except
> "history".

As a rule, I personally avoid methods whenever reasonable. The primary
reason is that the function versions generally work fine on lists,
giving my functions some extra genericity for free. I generally make
an exception only for attributes - X.shape, for example, rather than
np.shape(X).

It's true, it's a mess, but I'd just set down some simple rules that
work, and mention that some functions exist in other forms. There's
something to be said for rationalizing numpy's rules - or at least
writing them down! - but there's no need to use every version of every
function. And I believe they're all accessible as module-level
functions.

Anne


More information about the Numpy-discussion mailing list