On Sun, Aug 30, 2020 at 7:28 AM Barry <barry@barrys-emacs.org> wrote:
How is it supposed to work with set or dict or other iterables without clear order?
see the discussion in another recent thread about making dict indexable -- which looks like it's not going to happen.
so no -- this should not work with general iterables, indexes don't really make sense for iterables, only Sequences. Is your use of such a function so performance sensitive that you need this
in C? Have you considered writing this as a C extension for your own use?
or use numpy :-) (which is probably where the name "argmin" came from, rather than "index_min") Signature: np.argmin(a, axis=None, out=None) Docstring: Returns the indices of the minimum values along an axis. Parameters ---------- a : array_like Input array. axis : int, optional By default, the index is into the flattened array, otherwise along the specified axis. out : array, optional If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. Returns ------- index_array : ndarray of ints Array of indices into the array. It has the same shape as `a.shape` with the dimension along `axis` removed The other question of course, is what to do when the minimum value appears more than once -- numpy appears to give the first occurance: In [6]: np.argmin([3,2,1,2,3,4,5,1,2,3]) Out[6]: 2 -CHB -- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython