[Numpy-discussion] request for new array method: arr.abs()

Fernando Perez fperez.net at gmail.com
Wed Aug 23 19:46:15 EDT 2006


On 8/23/06, Bill Baxter <wbaxter at gmail.com> wrote:
> The thing that I find I keep forgetting is that abs() is a built-in, but
> other simple functions are not.  So it's abs(foo), but numpy.floor(foo) and
> numpy.ceil(foo).  And then there's round() which is a built-in but can't be
> used with arrays, so numpy.round_(foo).    Seems like it would be more
> consistent to just add a numpy.abs() and numpy.round().
>
> But I guess there's nothing numpy can do about it...  you can't name a
> method the same as a built-in function, right?  That's why we have
> numpy.round_() instead of numpy.round(), no?
> [...goes and checks]
> Oh, you *can* name a module function the same as a built-in.  Hmm... so then
> why isn't numpy.round_() just numpy.round()?  Is it just so "from numpy
> import *" won't hide the built-in?

Technically numpy could simply have (illustrated with round, but works
also with abs)

round = round_

and simply NOT include round in the __all__ list.  This would make

numpy.round(x)

work (clean syntax) while

from numpy import *

would not clobber the builtin round.  That sounds like a decent solution to me.

Cheers,

f




More information about the NumPy-Discussion mailing list