[Numpy-discussion] numpythonically getting elements with the minimum sum

Lluís xscript at gmx.net
Mon Jan 28 17:15:00 EST 2013


Hi,

I have a somewhat convoluted N-dimensional array that contains information of a
set of experiments.

The last dimension has as many entries as iterations in the experiment (an
iterative application), and the penultimate dimension has as many entries as
times I have run that experiment; the rest of dimensions describe the features
of the experiment:

    data.shape == (... indefinite amount of dimensions ..., NUM_RUNS, NUM_ITERATIONS)

So, what I want is to get the data for the best run of each experiment:

    best.shape == (... indefinite amount of dimensions ..., NUM_ITERATIONS)

by selecting, for each experiment, the run with the lowest total time (sum of
the time of all iterations for that experiment).


So far I've got the trivial part, but not the final indexing into "data":

    dsum = data.sum(axis = -1)
    dmin = dsum.min(axis = -1)
    best = data[???]


I'm sure there must be some numpythonic and generic way to get what I want, but
fancy indexing is beating me here :)


Thanks a lot!
  Lluis

-- 
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth



More information about the NumPy-Discussion mailing list