Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Find index of maximal element in multi-dimensional array

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73521] Re: [mg73492] Find index of maximal element in multi-dimensional array
  • From: János <janos.lobb at yale.edu>
  • Date: Wed, 21 Feb 2007 01:41:48 -0500 (EST)
  • References: <200702201115.GAA07673@smc.vnet.net>

On Feb 20, 2007, at 6:15 AM, 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
>

Here is a newbie approach:


Position[z, Max[Flatten[z]]]

J=E1nos


----------------------------------------------
Trying to argue with a politician is like lifting up the head of a 
corpse.
(S. Lem: His Master Voice)



  • Prev by Date: Re: Find index of maximal element in multi-dimensional array
  • Next by Date: Re: To dual-core or not to dual-core
  • Previous by thread: Re: Find index of maximal element in multi-dimensional array
  • Next by thread: Re: Find index of maximal element in multi-dimensional array