John Hunter wrote: > BTW, numpy gurus, is there a better way to find the index in an array > that is minimal than > > indmin = int(numpy.nonzero(distances.min()==distances)[0])
yes -- see below. Also a few tweaks: > distances = numpy.array(numpy.sqrt((x-xs[event.ind])**2. + > (y-ys[event.ind])**2)) No need to call numpy.array on that, you're making a copy of what must be an array already. By the way, if you're not sure if it's an array, then you can use numpy.asarray(a) which won't make a copy if the argument is already an array. You can also use numpy.hypot() rather than explicitly calling sqrt(SumOfSquares): distances = numpy.hypot(x-xs[event.ind], y-ys[event.ind] ) (untested) or, if all you want is the closest one, you don't need to take the sqrt() at all: distances = ( (x-xs[event.ind])**2 + (y-ys[event.ind])**2 ) And don't use "2." in an exponent -- I think there is some optimization for integer exponents. > indmin = int(numpy.nonzero(distances.min()==distances)[0]) here you can use argmin: indmin = numpy.argmin(distances) of course, what you'd really want is a spatial index.... All untested.... -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users