[Numpy-discussion] Adding .abs() method to the array object
Charles R Harris
charlesr.harris@gmail....
Mon Feb 25 11:07:21 CST 2013
On Mon, Feb 25, 2013 at 8:50 AM, Skipper Seabold <jsseabold@gmail.com>wrote:
> On Mon, Feb 25, 2013 at 10:43 AM, Till Stensitzki <mail.till@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.ctypes x.imag x.ravel x.strides
> x.any x.cumprod x.item x.real x.sum
> x.argmax x.cumsum x.itemset x.repeat x.swapaxes
> x.argmin x.data x.itemsize x.reshape x.take
> x.argsort x.diagonal x.max x.resize x.tofile
> x.astype x.dot x.mean x.round x.tolist
> x.base x.dtype x.min x.searchsorted x.tostring
> x.byteswap x.dump x.nbytes x.setfield x.trace
> x.choose x.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.
>
>
Somehow, this reminds me of I. N. Hersteins book, Topics in
Algebra<http://tinyurl.com/apoerwn>,
where he did function composition left-to-right instead of right-to-left.
>From a practical reading and typing point of view, left-to-right makes
sense, to add a new function you don't need to go way back to the beginning
of a line and you don't need to read right-to-left to see what is going on.
However, the line eventually gets too long, line breaks are inconvenient,
and you eventually forget what was at the beginning. I think short
left-to-right sequences are very nice. OTOH, one call/line is a bit like
left-to-right, only up-to-down, and there is no right margin, but you do
save the output generated on the previous line.
Herstein's attempt to revolutionise old algebraic habits never caught on.
But it was a bold attempt ;)
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130225/829c41a5/attachment.html
More information about the NumPy-Discussion
mailing list