[Numpy-discussion] The right way to use results of argmax and argmin
Victor S. Miller
victor at idaccr.org
Wed Apr 17 15:25:24 EDT 2002
# I'm running python 2.0 on Solaris and Numeric 21.0
#I have an m by n array -- called a and have
# j an n long list of integers in range(m), such as
j = argmax(a,0)
# If I set
z = zip(j,range(len(j)))
# and try the statement
res = take(a,z)
# python appears to hang, but if I do
res = array(map(lambda x,a=a: a[x,x]],z)
# It works.
# Is there a simpler way of doing what I want, and why does take hang?
# is it, perhaps, allocating some n by n work array (this would
# probably make things thrash like crazy)?
Victor S. Miller | " ... Meanwhile, those of us who can compute can hardly
victor at idaccr.org | be expected to keep writing papers saying 'I can do the
CCR, Princeton, NJ | following useless calculation in 2 seconds', and indeed
08540 USA | what editor would publish them?" -- Oliver Atkin
More information about the NumPy-Discussion