Re: Find index of maximal element in multi-dimensional array
- To: mathgroup at smc.vnet.net
- Subject: [mg73591] Re: Find index of maximal element in multi-dimensional array
- From: "Dana DeLouis" <dana.del at gmail.com>
- Date: Thu, 22 Feb 2007 04:41:16 -0500 (EST)
> The output is like this: > {{5, 4}, 0.921344} Hi. One of many ways... SeedRandom[2]; z = Table[Random[], {5}, {6}]; Position[z, Max[z]] /. (v_)?VectorQ :> {v, Extract[z, v]} {{{4, 3}, 0.9585506645732469}} -- HTH Dana DeLouis Windows XP & Mathematica 5.2 "Andrew Moylan" <andrew.j.moylan at gmail.com> wrote in message news:erelbt$7h4$1 at smc.vnet.net... > 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 > >