[Numpy-discussion] Keywords in wrapped functions

Travis E. Oliphant oliphant at enthought.com
Tue Jun 24 14:48:04 EDT 2008


Pierre GM wrote:
> All,
> Sorry to bumpt the post, accept my apologies for my rudeness, but I'm 
> curious...
> So, let me rephrase my question:
>
> Many numpy functions (min, max, sum...) based on ndarray methods have a 
> construction of the style
> #-----------------------------------------------
> def amin(a, axis=None, out=None):
>     try:
>         amin = a.min
>     except AttributeError:
>         return _wrapit(a, 'min', axis, out)
>     return amin(axis, out)
> #-----------------------------------------------
>
> I'm wondering why the initial keywords arguments are transformed into 
> positional arguments in the return. In the previous example, I would expect a 
> line like
> return amin(axis=axis, out=out)
>
> [Actually, I would even prefer a 
> return amin(axis=axis, out=out, **other_optional_parameters), which would 
> permit to add some extra parameters such as a "fill_value", when dealing with 
> masked arrays ?]
>
> Is this for efficiency purposes ?
>
>
>   
The keyword arguments to the methods were added later and so positional 
argument were initially necessary.  I don't think they are now, but I 
have not verified that.

-Travis




More information about the NumPy-Discussion mailing list