[Numpy-discussion] Proposal of new function: iteraxis()
Charles R Harris
Thu Apr 25 15:04:31 CDT 2013
On Thu, Apr 25, 2013 at 1:51 PM, <email@example.com> wrote:
> On Thu, Apr 25, 2013 at 3:40 PM, Robert Kern <firstname.lastname@example.org>
> > On Thu, Apr 25, 2013 at 8:21 PM, Andrew Giessel
> > <email@example.com> wrote:
> >> I respect this opinion. However (and maybe this is legacy), while
> >> through the numeric.py source file, I was surprised at how short many
> of the
> >> functions are, generally. Functions like ones() and zeros() are pretty
> >> simple wrappers which call empty() and then copy over values.
> > Many of these are short, but they do tend to do at least two things
> > that someone would otherwise have to do. This really isn't the case
> > for iteraxis() and rollaxis(). One can use rollaxis() pretty much
> > everywhere you would use iteraxis(), but not vice-versa.
> >> FWIW, I had used numpy for over two years before realizing that the
> >> behavior of iterating on a numpy array was to return slices over the
> >> axis (although, this makes sense because it makes a 1d array like a
> >> and I think it is generally left out of any tutorials or guides.
> That definitely sounds like a documentation problem.
> I'm using often that it's a python iterator in the first dimension,
> and can be used with *args and tuple unpacking.
> (I didn't need it with anything else than axis=0 or axis=-1 for matplotlib
> I never used rollaxis, but I have seen it a lot when I was still
> reading the nipy source.
> In general, I think that there are already too many aliases in numpy,
> or function whether it's not really clear if they are aliases or
> something slightly different.
> It took me more than a year to remember what `expand_dims` is called,
> (I always tried, add_axis) until I bookmarked it for a while.
After thinking about it, I'm in favor of this small function. Rollaxis
takes a bit of thought and document reading to figure out how to use it,
whereas this function covers a common use with an easy to understand API.
I'm not completely satisfied with the name, it isn't as memorable as I'd
like, but that is a small quibble.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion