Re: Find index of maximal element in multi-dimensional array
- To: mathgroup at smc.vnet.net
- Subject: [mg73533] Re: [mg73492] Find index of maximal element in multi-dimensional array
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Wed, 21 Feb 2007 01:48:19 -0500 (EST)
- References: <200702201115.GAA07673@smc.vnet.net>
On 20 Feb 2007, at 12:15, Andrew Moylan wrote: > Hi all, > > Here's a two-dimensional array of numbers: > > z = Table[Random[], {5}, {6}] > > What's an efficient way of finding the index of the maximal element of > z? Here's one way: > > Last[Sort[Flatten[MapIndexed[{#2, #1} & , z, {2}], 1], > OrderedQ[{#1[[2]], #2[[2]]}] & ]] > > The output is like this: > > {{5, 4}, 0.921344} > > But it's so untidy. Any better ideas? > > Cheers, > > Andrew > > If your list contains only numbers you can do this: z = Table[Random[], {5}, {6}]; Position[z, Max[z]] {{3, 6}} and then Extract[z, %] {0.9856362205505433} Andrzej Kozlowski
- References:
- Find index of maximal element in multi-dimensional array
- From: "Andrew Moylan" <andrew.j.moylan@gmail.com>
- Find index of maximal element in multi-dimensional array