outer idiom (was Re: [Numpy-discussion] Getting the indexes of themyarray.min())
perry at stsci.edu
Thu May 13 14:31:01 CDT 2004
Álvaro Tejero Cantero wrote:
> but this gives
> >>> subtract.outer(r,r).shape
> (10, 3, 10, 3)
> that is, subtracts y coordinates to x coordinates which is not intended.
> AFAIK the outer solution is MUCH faster than the nested for loops, so
> what I do now is
> >>> r_rel = transpose(array([subtract.outer(r[:,0],r[:,0]),
> >>> r_rel.shape #as with the double loop
> My question is then if there is any more elegant way to do this,
> especially giving as a result independence of the number of dimensions).
Not that I can think of at the moment.
> Maybe an "axis" (=0 in this case?) keyword for the outer function would
> be useful in this context?
Perhaps. Right now these ufunc methods are pretty complicated so
it may not be easy to do, but I understand that there is certainly
utility in being able to do that. We'll look into it (but not
right away so don't hold your breath).
More information about the Numpy-discussion