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

Sebastian Haase haase at msg.ucsf.edu
Wed Aug 23 23:22:32 CDT 2006


Travis Oliphant wrote:
> Sebastian Haase wrote:
>> On Wednesday 23 August 2006 18:37, Travis Oliphant wrote:
>>   
>>> David M. Cooke wrote:
>>>     
>>>> On Wed, 23 Aug 2006 16:22:52 -0700
>>>>
>>>> Sebastian Haase <haase at msg.ucsf.edu> wrote:
>>>>       
>>>>> On Wednesday 23 August 2006 16:12, Bill Baxter 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().
>>>>>>           
>>>>> Regarding the original subject:
>>>>> a) "absolute" is impractically too much typing and
>>>>> b) I just thought some (module-) functions might be "forgotten" to be
>>>>> put in as (object-) methods ... !?
>>>>>         
>>>> Four-line change, so I added a.abs() (three lines for array, one
>>>> for MaskedArray).
>>>>       
>>> While I appreciate it's proactive nature, I don't like this change
>>> because it adds another "ufunc" as a method.  Right now, I think conj is
>>> the only other method like that.
>>>
>>> Instead, I like better the idea of adding abs, round, max, and min to
>>> the "non-import-*" namespace of numpy.
>>>
>>>     
>> How does this compare with
>> mean, min, max, average
>> ?
>>   
> 
> I'm not sure what this question is asking, so I'll answer what I think 
> it is asking.
> 
> The mean, min, max, and average functions are *not* ufuncs.   They are 
> methods of particular ufuncs. 
> 
Yes - that's what  wanted to hear !  I'm just trying to bring in the 
"user's" point of view:  Not thinking about how they are implemented 
under the hood:  mean,min,max,average  have a very similar "feeling" to 
them as "abs".
I'm hoping this ("seeing things from the user p.o.v.") can stay like 
that for as long as possible !
Numpy should be focused on "scientist not programers".


(This is just why I posted this comment about "arr.abs()"  -  but if 
there is a good reason to not have this for "simplicity reasons 'under 
the hood'"  I can see that perfectly fine !)

- Sebastian






More information about the Numpy-discussion mailing list