MathGroup Archive 2010

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

Search the Archive

Re: Select Maximum Value

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107943] Re: Select Maximum Value
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Wed, 3 Mar 2010 05:53:07 -0500 (EST)

On 3/2/10 at 3:36 AM, graser at gmail.com (graser) wrote:

>I want to pick up the maximum value of each list  in the Array

>A={{2, 4, 1, 3, 2, 2}, {4,7,9,1,2,4}}

>I can do it in two steps..

>B=Table[Sort[A[[i]], #1>#2&], {i, 1, Length[A]}];

>C=Table[B[i], {i, 1, Length[B]}];

>But is there any way I can do it in just one step with Select
>function or any thing else?

There are several problems with your code. First, it is unwise
to use uppercase letters as variables since in several cases
that will conflict with built-in symbols. In particular an upper
case C has a built-in meaning.

You have defined b to be a 2-D array. Yet the code for setting
the value of c treats b as a function. I assume you meant the
following where I have changed your variables to lower case:

a = {{2, 4, 1, 3, 2, 2}, {4, 7, 9, 1, 2, 4}};
b = Table[Sort[a[[i]], #1 > #2 &], {i, 1, Length[a]}];
c = Table[b[[i]], {i, 1, Length[b]}];

Note, the code here that creates b is an identity function.

The following does the same thing in one step

In[4]:= d = Reverse[Sort@#] & /@ a;
{d == b, d == c}

Out[5]= {True,True}

But this clearly does not find the maximum value of each list.
That would be done as

In[6]:= Max /@ a

Out[6]= {4,9}

Or perhaps you wanted this

In[7]:= Max /@ Transpose[a]

Out[7]= {4,7,9,3,2,4}



  • Prev by Date: Re: Re: Harmonic Numbers
  • Next by Date: Re: Behavior of Longest
  • Previous by thread: Re: Select Maximum Value
  • Next by thread: Re: Re: Select Maximum Value