Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-26 Thread Pierre Haessig
Hi,

Le 23/02/2013 20:25, Nathaniel Smith a écrit :
 My gut feeling is that we have too many methods on ndarray, not too
 few, but in any case, can you elaborate? What's the rationale for why
 np.abs(a) is so much harder than a.abs(), and why this function and
 not other unary functions?
(Just another usecase where I see the x.abs() notation useful)

If x is a complex array, I feel that x.abs() and x.angle() would be
natural complements to x.real and x.imag.

Of course, x.angle() only make much sense for complex arrays while
x.abs() makes sense for any numerical array.

best,
Pierre



signature.asc
Description: OpenPGP digital signature
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-26 Thread Todd
On Tue, Feb 26, 2013 at 10:58 AM, Sebastian Berg sebast...@sipsolutions.net
 wrote:

 On Mon, 2013-02-25 at 22:04 -0500, josef.p...@gmail.com wrote:
  On Mon, Feb 25, 2013 at 9:58 PM,  josef.p...@gmail.com wrote:
   On Mon, Feb 25, 2013 at 9:20 PM, Sebastian Berg
   sebast...@sipsolutions.net wrote:
   On Mon, 2013-02-25 at 10:50 -0500, Skipper Seabold wrote:
   On Mon, Feb 25, 2013 at 10:43 AM, Till Stensitzki mail.t...@gmx.de
   wrote:
   
First, sorry that i didnt search for an old thread, but because i
   disagree with
conclusion i would at least address my reason:
   
 snip
   Two small things (not sure if it matters much). But first almost all
 of
   these methods are related to the container and not the elements.
 Second
   actually using a method arr.abs() has a tiny pitfall, since abs would
   work on numpy types, but not on python types. This means that:
  
   np.array([1, 2, 3]).max().abs()
  
   works, but
  
   np.array([1, 2, 3], dtype=object).max().abs()
  
   breaks. Python has a safe name for abs already...
  
   (np.array([1, 2, 3], dtype=object)).max()
   3
   (np.array([1, 2, 3], dtype=object)).__abs__().max()
   3
   (np.array([1, 2, '3'], dtype=object)).__abs__()
   Traceback (most recent call last):
 File stdin, line 1, in module
   TypeError: bad operand type for abs(): 'str'
  
   map(abs, [1, 2, 3])
   [1, 2, 3]
   map(abs, [1, 2, '3'])
   Traceback (most recent call last):
 File stdin, line 1, in module
   TypeError: bad operand type for abs(): 'str'
 
  or maybe more useful
 
   from decimal import Decimal
   d = [Decimal(str(k)) for k in np.linspace(-1, 1, 5)]
   map(abs, d)
  [Decimal('1.0'), Decimal('0.5'), Decimal('0.0'), Decimal('0.5'),
 Decimal('1.0')]
 
   np.asarray(d).__abs__()
  array([1.0, 0.5, 0.0, 0.5, 1.0], dtype=object)
   np.asarray(d).__abs__()[0]
  Decimal('1.0')
 
  Josef
 
  
   I don't see a difference.
  
   (I don't expect to use max abs on anything else than numbers.)
  

 The difference is about scalars only. And of course __abs__ is fine, but
 if numpy adds an abs method, its scalars would logically have it too.
 But then you diverge from python scalars. That has exactly the downside
 that you may write code that suddenly stops working for python scalars
 without noticing.

 I turned around the abs and max order here, so that the abs works on the
 scalar, not useful but just as an example.


But doesn't this also apply to many existing methods?
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-26 Thread Robert Kern
On Tue, Feb 26, 2013 at 12:11 AM, Charles R Harris
charlesr.har...@gmail.com wrote:

 On Sat, Feb 23, 2013 at 1:33 PM, Robert Kern robert.k...@gmail.com wrote:

 On Sat, Feb 23, 2013 at 7:25 PM, Nathaniel Smith n...@pobox.com wrote:
  On Sat, Feb 23, 2013 at 3:38 PM, Till Stensitzki mail.t...@gmx.de
  wrote:
  Hello,
  i know that the array object is already crowded, but i would like
  to see the abs method added, especially doing work on the console.
  Considering that many much less used functions are also implemented
  as a method, i don't think adding one more would be problematic.
 
  My gut feeling is that we have too many methods on ndarray, not too
  few, but in any case, can you elaborate? What's the rationale for why
  np.abs(a) is so much harder than a.abs(), and why this function and
  not other unary functions?

 Or even abs(a).


 Well, that just calls a method:

 In [1]: ones(3).__abs__()
 Out[1]: array([ 1.,  1.,  1.])

 Which shows the advantage of methods, they provide universal function hooks.

I'm not sure what point you are trying to make. It does not appear to
be relevant to adding an ndarray.abs() method.

-- 
Robert Kern
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-25 Thread Till Stensitzki

First, sorry that i didnt search for an old thread, but because i disagree with 
conclusion i would at least address my reason:

 I don't like
 np.abs(arr).max()
 because I have to concentrate to much on the braces, especially if arr
 is a calculation

This exactly, adding an abs into an old expression is always a little annoyance
due to the parenthesis. The argument that np.abs() also works is true for
(almost?) every other method. The fact that so many methods already exists,
especially for most of the commonly used functions (min, max, dot, mean, std,
argmin, argmax, conj, T) makes me missing abs. Of course, if one would redesign
the api, one would drop most methods (i am looking at you ptp and byteswap). But
the objected is already cluttered and adding abs is imo logical application of
practicality beats purity.

greetings
Till


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-25 Thread Frédéric Bastien
On Sat, Feb 23, 2013 at 9:34 PM, Benjamin Root ben.r...@ou.edu wrote:

 My issue is having to remember which ones are methods and which ones are
 functions.  There doesn't seem to be a rhyme or reason for the choices, and
 I would rather like to see that a line is drawn, but I am not picky as to
 where it is drawn.

I like that. I think it would be a good idea to find a good line for
NumPy 2.0. As we already will break the API, why not break it for
another part at the same time.

I don't have any idea what would be a good line... Do someone have a
good idea? Do you agree that it would be a good idea for 2.0?

Fred
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-25 Thread Skipper Seabold
On Mon, Feb 25, 2013 at 10:43 AM, Till Stensitzki mail.t...@gmx.de wrote:

 First, sorry that i didnt search for an old thread, but because i
disagree with
 conclusion i would at least address my reason:

 I don't like
 np.abs(arr).max()
 because I have to concentrate to much on the braces, especially if arr
 is a calculation

 This exactly, adding an abs into an old expression is always a little
annoyance
 due to the parenthesis. The argument that np.abs() also works is true for
 (almost?) every other method. The fact that so many methods already
exists,
 especially for most of the commonly used functions (min, max, dot, mean,
std,
 argmin, argmax, conj, T) makes me missing abs. Of course, if one would
redesign
 the api, one would drop most methods (i am looking at you ptp and
byteswap). But
 the objected is already cluttered and adding abs is imo logical
application of
 practicality beats purity.


I tend to agree here. The situation isn't all that dire for the number of
methods in an array. No scrolling at reasonably small terminal sizes.

[~/]
[3]: x.
x.T x.copy  x.getfield  x.put   x.std
x.all   x.ctypesx.imag  x.ravel x.strides
x.any   x.cumprod   x.item  x.real  x.sum
x.argmaxx.cumsumx.itemset   x.repeatx.swapaxes
x.argminx.data  x.itemsize  x.reshape   x.take
x.argsort   x.diagonal  x.max   x.resizex.tofile
x.astypex.dot   x.mean  x.round x.tolist
x.base  x.dtype x.min   x.searchsorted  x.tostring
x.byteswap  x.dump  x.nbytesx.setfield  x.trace
x.choosex.dumps x.ndim  x.setflags  x.transpose
x.clip  x.fill  x.newbyteorder  x.shape x.var
x.compress  x.flags x.nonzero   x.size  x.view
x.conj  x.flat  x.prod  x.sort
x.conjugate x.flatten   x.ptp   x.squeeze


I find myself typing things like

arr.abs()

and

arr.unique()

quite often.

Skipper
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-25 Thread Charles R Harris
On Sat, Feb 23, 2013 at 1:33 PM, Robert Kern robert.k...@gmail.com wrote:

 On Sat, Feb 23, 2013 at 7:25 PM, Nathaniel Smith n...@pobox.com wrote:
  On Sat, Feb 23, 2013 at 3:38 PM, Till Stensitzki mail.t...@gmx.de
 wrote:
  Hello,
  i know that the array object is already crowded, but i would like
  to see the abs method added, especially doing work on the console.
  Considering that many much less used functions are also implemented
  as a method, i don't think adding one more would be problematic.
 
  My gut feeling is that we have too many methods on ndarray, not too
  few, but in any case, can you elaborate? What's the rationale for why
  np.abs(a) is so much harder than a.abs(), and why this function and
  not other unary functions?

 Or even abs(a).


Well, that just calls a method:

In [1]: ones(3).__abs__()
Out[1]: array([ 1.,  1.,  1.])

Which shows the advantage of methods, they provide universal function hooks.

Chuck
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-25 Thread josef . pktd
On Mon, Feb 25, 2013 at 7:11 PM, Charles R Harris
charlesr.har...@gmail.com wrote:


 On Sat, Feb 23, 2013 at 1:33 PM, Robert Kern robert.k...@gmail.com wrote:

 On Sat, Feb 23, 2013 at 7:25 PM, Nathaniel Smith n...@pobox.com wrote:
  On Sat, Feb 23, 2013 at 3:38 PM, Till Stensitzki mail.t...@gmx.de
  wrote:
  Hello,
  i know that the array object is already crowded, but i would like
  to see the abs method added, especially doing work on the console.
  Considering that many much less used functions are also implemented
  as a method, i don't think adding one more would be problematic.
 
  My gut feeling is that we have too many methods on ndarray, not too
  few, but in any case, can you elaborate? What's the rationale for why
  np.abs(a) is so much harder than a.abs(), and why this function and
  not other unary functions?

 Or even abs(a).


 Well, that just calls a method:

 In [1]: ones(3).__abs__()
 Out[1]: array([ 1.,  1.,  1.])

 Which shows the advantage of methods, they provide universal function hooks.

Maybe we should start to advertise magic methods.
I only recently discovered I can use divmod instead of the numpy functions:

 divmod(np.array([1.4]), 1)
(array([ 1.]), array([ 0.4]))
 np.array([1.4]).__divmod__(1)
(array([ 1.]), array([ 0.4]))

Josef



 Chuck

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-25 Thread josef . pktd
On Mon, Feb 25, 2013 at 7:49 PM,  josef.p...@gmail.com wrote:
 On Mon, Feb 25, 2013 at 7:11 PM, Charles R Harris
 charlesr.har...@gmail.com wrote:


 On Sat, Feb 23, 2013 at 1:33 PM, Robert Kern robert.k...@gmail.com wrote:

 On Sat, Feb 23, 2013 at 7:25 PM, Nathaniel Smith n...@pobox.com wrote:
  On Sat, Feb 23, 2013 at 3:38 PM, Till Stensitzki mail.t...@gmx.de
  wrote:
  Hello,
  i know that the array object is already crowded, but i would like
  to see the abs method added, especially doing work on the console.
  Considering that many much less used functions are also implemented
  as a method, i don't think adding one more would be problematic.
 
  My gut feeling is that we have too many methods on ndarray, not too
  few, but in any case, can you elaborate? What's the rationale for why
  np.abs(a) is so much harder than a.abs(), and why this function and
  not other unary functions?

 Or even abs(a).


 Well, that just calls a method:

 In [1]: ones(3).__abs__()
 Out[1]: array([ 1.,  1.,  1.])

 Which shows the advantage of methods, they provide universal function hooks.

 Maybe we should start to advertise magic methods.
 I only recently discovered I can use divmod instead of the numpy functions:

 divmod(np.array([1.4]), 1)
 (array([ 1.]), array([ 0.4]))
 np.array([1.4]).__divmod__(1)
 (array([ 1.]), array([ 0.4]))

Thanks for the hint.

my new favorite :)

 (freq - nobs * probs).__abs__().max()
132.0

Josef


 Josef



 Chuck

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-25 Thread Sebastian Berg
On Mon, 2013-02-25 at 10:50 -0500, Skipper Seabold wrote:
 On Mon, Feb 25, 2013 at 10:43 AM, Till Stensitzki mail.t...@gmx.de
 wrote:
 
  First, sorry that i didnt search for an old thread, but because i
 disagree with
  conclusion i would at least address my reason:
 
  I don't like
  np.abs(arr).max()
  because I have to concentrate to much on the braces, especially if
 arr
  is a calculation
 
  This exactly, adding an abs into an old expression is always a
 little annoyance
  due to the parenthesis. The argument that np.abs() also works is
 true for
  (almost?) every other method. The fact that so many methods already
 exists,
  especially for most of the commonly used functions (min, max, dot,
 mean, std,
  argmin, argmax, conj, T) makes me missing abs. Of course, if one
 would redesign
  the api, one would drop most methods (i am looking at you ptp and
 byteswap). But
  the objected is already cluttered and adding abs is imo logical
 application of
  practicality beats purity.
 
 
 I tend to agree here. The situation isn't all that dire for the number
 of methods in an array. No scrolling at reasonably small terminal
 sizes.
 
 [~/]
 [3]: x.
 x.T x.copy  x.getfield  x.put   x.std
 x.all   x.ctypesx.imag  x.ravel
 x.strides
 x.any   x.cumprod   x.item  x.real  x.sum
 x.argmaxx.cumsumx.itemset   x.repeat
  x.swapaxes
 x.argminx.data  x.itemsize  x.reshape   x.take
 x.argsort   x.diagonal  x.max   x.resize
  x.tofile
 x.astypex.dot   x.mean  x.round
 x.tolist
 x.base  x.dtype x.min   x.searchsorted
  x.tostring
 x.byteswap  x.dump  x.nbytesx.setfield
  x.trace
 x.choosex.dumps x.ndim  x.setflags
  x.transpose
 x.clip  x.fill  x.newbyteorder  x.shape x.var
 x.compress  x.flags x.nonzero   x.size  x.view
 x.conj  x.flat  x.prod  x.sort  
 x.conjugate x.flatten   x.ptp   x.squeeze   
 
 
Two small things (not sure if it matters much). But first almost all of
these methods are related to the container and not the elements. Second
actually using a method arr.abs() has a tiny pitfall, since abs would
work on numpy types, but not on python types. This means that:

np.array([1, 2, 3]).max().abs()

works, but

np.array([1, 2, 3], dtype=object).max().abs()

breaks. Python has a safe name for abs already...


 I find myself typing things like 
 
 arr.abs()
 
 and
 
 arr.unique()
 
 quite often.
 
 Skipper
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-25 Thread josef . pktd
On Mon, Feb 25, 2013 at 9:20 PM, Sebastian Berg
sebast...@sipsolutions.net wrote:
 On Mon, 2013-02-25 at 10:50 -0500, Skipper Seabold wrote:
 On Mon, Feb 25, 2013 at 10:43 AM, Till Stensitzki mail.t...@gmx.de
 wrote:
 
  First, sorry that i didnt search for an old thread, but because i
 disagree with
  conclusion i would at least address my reason:
 
  I don't like
  np.abs(arr).max()
  because I have to concentrate to much on the braces, especially if
 arr
  is a calculation
 
  This exactly, adding an abs into an old expression is always a
 little annoyance
  due to the parenthesis. The argument that np.abs() also works is
 true for
  (almost?) every other method. The fact that so many methods already
 exists,
  especially for most of the commonly used functions (min, max, dot,
 mean, std,
  argmin, argmax, conj, T) makes me missing abs. Of course, if one
 would redesign
  the api, one would drop most methods (i am looking at you ptp and
 byteswap). But
  the objected is already cluttered and adding abs is imo logical
 application of
  practicality beats purity.
 

 I tend to agree here. The situation isn't all that dire for the number
 of methods in an array. No scrolling at reasonably small terminal
 sizes.

 [~/]
 [3]: x.
 x.T x.copy  x.getfield  x.put   x.std
 x.all   x.ctypesx.imag  x.ravel
 x.strides
 x.any   x.cumprod   x.item  x.real  x.sum
 x.argmaxx.cumsumx.itemset   x.repeat
  x.swapaxes
 x.argminx.data  x.itemsize  x.reshape   x.take
 x.argsort   x.diagonal  x.max   x.resize
  x.tofile
 x.astypex.dot   x.mean  x.round
 x.tolist
 x.base  x.dtype x.min   x.searchsorted
  x.tostring
 x.byteswap  x.dump  x.nbytesx.setfield
  x.trace
 x.choosex.dumps x.ndim  x.setflags
  x.transpose
 x.clip  x.fill  x.newbyteorder  x.shape x.var
 x.compress  x.flags x.nonzero   x.size  x.view
 x.conj  x.flat  x.prod  x.sort
 x.conjugate x.flatten   x.ptp   x.squeeze


 Two small things (not sure if it matters much). But first almost all of
 these methods are related to the container and not the elements. Second
 actually using a method arr.abs() has a tiny pitfall, since abs would
 work on numpy types, but not on python types. This means that:

 np.array([1, 2, 3]).max().abs()

 works, but

 np.array([1, 2, 3], dtype=object).max().abs()

 breaks. Python has a safe name for abs already...

 (np.array([1, 2, 3], dtype=object)).max()
3
 (np.array([1, 2, 3], dtype=object)).__abs__().max()
3
 (np.array([1, 2, '3'], dtype=object)).__abs__()
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: bad operand type for abs(): 'str'

 map(abs, [1, 2, 3])
[1, 2, 3]
 map(abs, [1, 2, '3'])
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: bad operand type for abs(): 'str'

I don't see a difference.

(I don't expect to use max abs on anything else than numbers.)

Josef


 I find myself typing things like

 arr.abs()

 and

 arr.unique()

 quite often.

 Skipper
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-25 Thread josef . pktd
On Mon, Feb 25, 2013 at 9:58 PM,  josef.p...@gmail.com wrote:
 On Mon, Feb 25, 2013 at 9:20 PM, Sebastian Berg
 sebast...@sipsolutions.net wrote:
 On Mon, 2013-02-25 at 10:50 -0500, Skipper Seabold wrote:
 On Mon, Feb 25, 2013 at 10:43 AM, Till Stensitzki mail.t...@gmx.de
 wrote:
 
  First, sorry that i didnt search for an old thread, but because i
 disagree with
  conclusion i would at least address my reason:
 
  I don't like
  np.abs(arr).max()
  because I have to concentrate to much on the braces, especially if
 arr
  is a calculation
 
  This exactly, adding an abs into an old expression is always a
 little annoyance
  due to the parenthesis. The argument that np.abs() also works is
 true for
  (almost?) every other method. The fact that so many methods already
 exists,
  especially for most of the commonly used functions (min, max, dot,
 mean, std,
  argmin, argmax, conj, T) makes me missing abs. Of course, if one
 would redesign
  the api, one would drop most methods (i am looking at you ptp and
 byteswap). But
  the objected is already cluttered and adding abs is imo logical
 application of
  practicality beats purity.
 

 I tend to agree here. The situation isn't all that dire for the number
 of methods in an array. No scrolling at reasonably small terminal
 sizes.

 [~/]
 [3]: x.
 x.T x.copy  x.getfield  x.put   x.std
 x.all   x.ctypesx.imag  x.ravel
 x.strides
 x.any   x.cumprod   x.item  x.real  x.sum
 x.argmaxx.cumsumx.itemset   x.repeat
  x.swapaxes
 x.argminx.data  x.itemsize  x.reshape   x.take
 x.argsort   x.diagonal  x.max   x.resize
  x.tofile
 x.astypex.dot   x.mean  x.round
 x.tolist
 x.base  x.dtype x.min   x.searchsorted
  x.tostring
 x.byteswap  x.dump  x.nbytesx.setfield
  x.trace
 x.choosex.dumps x.ndim  x.setflags
  x.transpose
 x.clip  x.fill  x.newbyteorder  x.shape x.var
 x.compress  x.flags x.nonzero   x.size  x.view
 x.conj  x.flat  x.prod  x.sort
 x.conjugate x.flatten   x.ptp   x.squeeze


 Two small things (not sure if it matters much). But first almost all of
 these methods are related to the container and not the elements. Second
 actually using a method arr.abs() has a tiny pitfall, since abs would
 work on numpy types, but not on python types. This means that:

 np.array([1, 2, 3]).max().abs()

 works, but

 np.array([1, 2, 3], dtype=object).max().abs()

 breaks. Python has a safe name for abs already...

 (np.array([1, 2, 3], dtype=object)).max()
 3
 (np.array([1, 2, 3], dtype=object)).__abs__().max()
 3
 (np.array([1, 2, '3'], dtype=object)).__abs__()
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: bad operand type for abs(): 'str'

 map(abs, [1, 2, 3])
 [1, 2, 3]
 map(abs, [1, 2, '3'])
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: bad operand type for abs(): 'str'

or maybe more useful

 from decimal import Decimal
 d = [Decimal(str(k)) for k in np.linspace(-1, 1, 5)]
 map(abs, d)
[Decimal('1.0'), Decimal('0.5'), Decimal('0.0'), Decimal('0.5'), Decimal('1.0')]

 np.asarray(d).__abs__()
array([1.0, 0.5, 0.0, 0.5, 1.0], dtype=object)
 np.asarray(d).__abs__()[0]
Decimal('1.0')

Josef


 I don't see a difference.

 (I don't expect to use max abs on anything else than numbers.)

 Josef


 I find myself typing things like

 arr.abs()

 and

 arr.unique()

 quite often.

 Skipper
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-23 Thread Nathaniel Smith
On Sat, Feb 23, 2013 at 3:38 PM, Till Stensitzki mail.t...@gmx.de wrote:
 Hello,
 i know that the array object is already crowded, but i would like
 to see the abs method added, especially doing work on the console.
 Considering that many much less used functions are also implemented
 as a method, i don't think adding one more would be problematic.

My gut feeling is that we have too many methods on ndarray, not too
few, but in any case, can you elaborate? What's the rationale for why
np.abs(a) is so much harder than a.abs(), and why this function and
not other unary functions?

-n
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-23 Thread Charles R Harris
On Sat, Feb 23, 2013 at 12:25 PM, Nathaniel Smith n...@pobox.com wrote:

 On Sat, Feb 23, 2013 at 3:38 PM, Till Stensitzki mail.t...@gmx.de wrote:
  Hello,
  i know that the array object is already crowded, but i would like
  to see the abs method added, especially doing work on the console.
  Considering that many much less used functions are also implemented
  as a method, i don't think adding one more would be problematic.

 My gut feeling is that we have too many methods on ndarray, not too
 few, but in any case, can you elaborate? What's the rationale for why
 np.abs(a) is so much harder than a.abs(), and why this function and
 not other unary functions?


IIRC, there was a long thread about adding 'abs' back around 1.0.3-1.1.0
with Travis against it ;) I don't feel strongly one way or the other.

Chuck
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-23 Thread Robert Kern
On Sat, Feb 23, 2013 at 7:25 PM, Nathaniel Smith n...@pobox.com wrote:
 On Sat, Feb 23, 2013 at 3:38 PM, Till Stensitzki mail.t...@gmx.de wrote:
 Hello,
 i know that the array object is already crowded, but i would like
 to see the abs method added, especially doing work on the console.
 Considering that many much less used functions are also implemented
 as a method, i don't think adding one more would be problematic.

 My gut feeling is that we have too many methods on ndarray, not too
 few, but in any case, can you elaborate? What's the rationale for why
 np.abs(a) is so much harder than a.abs(), and why this function and
 not other unary functions?

Or even abs(a).

-- 
Robert Kern
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-23 Thread josef . pktd
On Sat, Feb 23, 2013 at 3:33 PM, Robert Kern robert.k...@gmail.com wrote:
 On Sat, Feb 23, 2013 at 7:25 PM, Nathaniel Smith n...@pobox.com wrote:
 On Sat, Feb 23, 2013 at 3:38 PM, Till Stensitzki mail.t...@gmx.de wrote:
 Hello,
 i know that the array object is already crowded, but i would like
 to see the abs method added, especially doing work on the console.
 Considering that many much less used functions are also implemented
 as a method, i don't think adding one more would be problematic.

 My gut feeling is that we have too many methods on ndarray, not too
 few, but in any case, can you elaborate? What's the rationale for why
 np.abs(a) is so much harder than a.abs(), and why this function and
 not other unary functions?

 Or even abs(a).


my reason is that I often use

arr.max()
but then decide I want to us abs and need
np.max(np.abs(arr))
instead of arr.abs().max() (and often I write that first to see the
error message)

I don't like
np.abs(arr).max()
because I have to concentrate to much on the braces, especially if arr
is a calculation

I wrote several times
def maxabs(arr):
return np.max(np.abs(arr))

silly, but I use it often and np.is_close is not useful (doesn't show how close)

Just a small annoyance, but I think it's the method that I miss most often.

Josef



 --
 Robert Kern
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Adding .abs() method to the array object

2013-02-23 Thread Benjamin Root
On Sat, Feb 23, 2013 at 8:20 PM, josef.p...@gmail.com wrote:

 On Sat, Feb 23, 2013 at 3:33 PM, Robert Kern robert.k...@gmail.com
 wrote:
  On Sat, Feb 23, 2013 at 7:25 PM, Nathaniel Smith n...@pobox.com wrote:
  On Sat, Feb 23, 2013 at 3:38 PM, Till Stensitzki mail.t...@gmx.de
 wrote:
  Hello,
  i know that the array object is already crowded, but i would like
  to see the abs method added, especially doing work on the console.
  Considering that many much less used functions are also implemented
  as a method, i don't think adding one more would be problematic.
 
  My gut feeling is that we have too many methods on ndarray, not too
  few, but in any case, can you elaborate? What's the rationale for why
  np.abs(a) is so much harder than a.abs(), and why this function and
  not other unary functions?
 
  Or even abs(a).


 my reason is that I often use

 arr.max()
 but then decide I want to us abs and need
 np.max(np.abs(arr))
 instead of arr.abs().max() (and often I write that first to see the
 error message)

 I don't like
 np.abs(arr).max()
 because I have to concentrate to much on the braces, especially if arr
 is a calculation

 I wrote several times
 def maxabs(arr):
 return np.max(np.abs(arr))

 silly, but I use it often and np.is_close is not useful (doesn't show how
 close)

 Just a small annoyance, but I think it's the method that I miss most often.

 Josef


My issue is having to remember which ones are methods and which ones are
functions.  There doesn't seem to be a rhyme or reason for the choices, and
I would rather like to see that a line is drawn, but I am not picky as to
where it is drawn.

Ben Root
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion