D
David Isaac
1. Why is there no argmax built-in?
(This would return the index of the largest element in a sequence.)
2. Is this a good argmax (as long as I know the iterable is finite)?
def argmax(iterable): return max(izip( iterable, count() ))[1]
3. If this is the only place in a module where I need count and izip,
should I import them at the module level or at the level of the function?
What are the considerations here?
Thanks,
Alan Isaac
(This would return the index of the largest element in a sequence.)
2. Is this a good argmax (as long as I know the iterable is finite)?
def argmax(iterable): return max(izip( iterable, count() ))[1]
3. If this is the only place in a module where I need count and izip,
should I import them at the module level or at the level of the function?
What are the considerations here?
Thanks,
Alan Isaac