[Numpy-discussion] contributing to numpy
Thu Apr 18 11:02:07 CDT 2013
An update--- I submitted a PR if anyone is interested:
Secondly, it was pointed out to my by Stefan van der Walt that one could
use np.rollaxis() to reorder an array such that the default iterator
behavior would yield the same slices of the array:
a = np.ones((100,10,3))
for i in np.rollaxis(a, 2):
gives you 3 100x10 slices.
My PR is more of a pure iterator, so I sent it in
all the best,
On Wed, Apr 17, 2013 at 2:18 PM, Andrew Giessel <
> Thank you for the very helpful and encouraging email! I will first try to
> just add a function, rather than a method on ndarray (which looks to be
> lower level ie: C). The pointer to numeric.py / test_numeric.py is exactly
> what I needed.
> I will of course figure out a good test and document it well. For
> starters, I'll make the function simply take an integer corresponding to an
> axis. I'm not exactly sure what you mean by generalizing to take multiple
> axes -- would the idea be to return slices of an array w/o one of the
> I'll try to tackle this over the next week and hopefully the conversation
> on the PR will be the place to talk about these issues. I'll need to
> figure out the best way to have a dev branch of numpy side-by-side with a
> stock version, and how to build the module, first.
> Lastly, I'll also try to write up something re: my experience so others
> can have something to take a look at.
> On Wed, Apr 17, 2013 at 11:43 AM, Charles R Harris <
> email@example.com> wrote:
>> On Wed, Apr 17, 2013 at 6:29 AM, andrew giessel <firstname.lastname@example.org
>> > wrote:
>>> First, my apologies if this isn't the right forum for this question- I
>>> looked for a dev list, but couldn't really find it.
>>> I have a small method I'd like to contribute to numpy, ideally as a
>>> method on ndarrays and a general function in the numpy namespace. I found
>>> it on a stackoverflow thread, and it is a generator that yields slices of a
>>> multidimensional array over a specified axis, which is convenient for use
>>> in list comprehensions and loops.
>>> I've forked the numpy source and am familar with git/pull requests/etc
>>> but the code base is a bit overwhelming.
>>> I have 2 questions:
>>> 1) Is there a document which gives an overview of the numpy source and
>>> perhaps a tutorial on the best way to add methods/functions?
>> The closest thing is probably Contributing to Numpy
>> which I suspect is not what you are looking for. At this point you pretty
>> much need to dig through the source to see how it is organized. To see how
>> things like tests/documentation are organized look for existing examples
>> and also the relevant docs in doc/.
>>> 2) is there a current way to do this in numpy? The only iterator
>>> related stuff I found in a brief search last night was for essentially
>>> looping over all elements of an array, one by one.
>> I think a function like this would be useful. There are ad-hoc ways to
>> get the same result but they aren't quite as flexible. A few comments
>> 1) The function would probably best go in numpy/core/numeric.py
>> 2) It will need a docstring
>> 3) It will need tests in numpy/core/tests/test_numeric.py
>> 4) xrange isn't Python 3 compatible, use range instead.
>> The name isn't very descriptive, maybe iter_over_axis? One possible
>> generalization would to let axis (axes) be either a number, or a list of
>> axes. The first being the number of leading axes, the second letting one
>> choose arbitrary axes.
>> NumPy-Discussion mailing list
> Andrew Giessel, PhD
> Department of Neurobiology, Harvard Medical School
> 220 Longwood Ave Boston, MA 02115
> ph: 617.432.7971 email: email@example.com
Andrew Giessel, PhD
Department of Neurobiology, Harvard Medical School
220 Longwood Ave Boston, MA 02115
ph: 617.432.7971 email: firstname.lastname@example.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion