How to find maximal entry in a Numpy array?
jhauser at ifm.uni-kiel.de
jhauser at ifm.uni-kiel.de
Sun May 2 06:59:34 EDT 1999
This can be used for all kind of indices.
HTH,
__Janko
##### cut here
def find_index(lin_index, sh):
"""
Translates flat indices to multidimensioanl indeces of an array
with shape sh
"""
sh = list(sh)
sh.reverse()
new_index = Numeric.zeros((len(lin_index), len(sh)))
mod = Numeric.zeros(len(lin_index))
for j in Numeric.arange(len(lin_index)):
count=len(sh)
for i in sh:
lin_index[j], mod[j] = divmod(lin_index[j], i)
count = count - 1
new_index[j, count] = mod[j]
return new_index
def find_max2(m):
"""Gives the indices of maximum value in m"""
return find_index([Numeric.argmax(m.flat)],m.shape)
--
Institut fuer Meereskunde phone: 49-431-597 3989
Dept. Theoretical Oceanography fax : 49-431-565876
Duesternbrooker Weg 20 email: jhauser at ifm.uni-kiel.de
24105 Kiel, Germany
More information about the Python-list
mailing list