From: Tim H. <tim...@co...> - 2004-05-12 20:13:48
|
Álvaro Tejero Cantero wrote: >Hello, > >I am new to numarray. I have been searching the documentation, and see >no evident vectorial and concise way to get the indexes for the minimum >of an array times.min(). > > If I understand your question correctly, you want argmin: >>> import numarray as na >>> from numarray import random_array >>> times = random_array.randint(0, 16, [4,4]) >>> times array([[15, 3, 11, 10], [ 1, 1, 15, 7], [ 4, 3, 5, 6], [10, 15, 12, 3]]) >>> na.argmin(times) # Takes min along axis 0 array([1, 1, 2, 3]) >>> na.argmin(times, 1) # Take min along axis 1 array([1, 1, 1, 3]) -tim >Currently my two alternatives are: (times is NxN array) > >husband, wife = nonzero(equal(times.min(),times)) >#gives tuple of 1x1 arrays, each containing one index > >and (even uglier) > >husband = compress(times.min()==times,indices([N,N])[0]) >wife = compress(times.min()==times,indices([N,N])[1]) > >These are weird ways to get something as simple. I am surely missing >something, but I have tried several slicing strategies before without >success. > >For getting the minimum times in each row I use: > >choose(argmin(times),transpose(times)) > >What are the idioms in numpy for these tasks? > > >Thank you very much in advance, á. > >I would > > > |