|
From: Ryan K. <rya...@gm...> - 2006-02-24 02:10:50
|
Is the right answer to just use flatten()?
i.e. ind=3Dabs(mymat).argmax()
maxelem=3Dmymat.flatten()[ind]
On 2/23/06, Ryan Krauss <rya...@gm...> wrote:
> Is this the expected behavior for array.argmax():
>
> ipdb> abs(real(disps)).max()
> Out[38]: 1.7373584411866401e-05
> ipdb> abs(real(disps)).argmax()
> Out[38]: 32
> ipdb> shape(disps)
> Out[38]: (11, 3)
> ipdb> disps[11,1]
> *** IndexError: invalid index
> ipdb> disps[10,1]
> Out[38]: 0j
> ipdb> disps[10,2]
> Out[38]: (-1.7373584411866401e-05+5.2046737124258386e-21j)
>
> Basically, I want to find the element with the largest absolute value
> in a matrix and use it to scale by. But I need to correct for the
> possibility that the largest abs value may be from a negative number.
> So, I need to get the corresponding element itself.
>
> My array is shape (11,3) and argmax without an axis argument returns
> 32, which would be the index if the matrix was reshaped into a (33,)
> vector. Is there a clean way to extract the element based on the
> output of argmax? (and in my case it is actually using the output of
> argmax to extract the element from the matrix without the abs). Or do
> I need to reshape the matrix into a vector first?
>
> Thanks,
>
> Ryan
>
|