Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

minimum and argmin in numpy

Tags:

python

numpy

Given an array I need to find the minimum and the position of the minimum. This can be done using

>>> current_cost
array([ 2.54802261,  2.98627555,  0.23873749,  1.82511195,  1.35469083])
>>> current_cost.min()
0.23873748917821858
>>> current_cost.argmin()
2

This solutions is not very efficient because it needs to scan the list two times. Is there a way to obtain minimum and agrmin at the same time?

like image 997
Donbeo Avatar asked Sep 27 '14 15:09

Donbeo


Video Answer


1 Answers

min_pos = current_cost.argmin()
min_val = current_cost[min_pos]
like image 194
pv. Avatar answered Sep 22 '22 00:09

pv.