MathGroup Archive 1998

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

Search the Archive

Re: Sorting of Data Lists



CFreitas@swri.edu wrote:
> 
> I have two equal length vector sets of data.  I wish to form a third
> vector  whose elements are the minimum values from each component of
> the other two  vectors; i.e., if a(i) < b(i), then c(i) = a(i), else
> c(i) = b(i).  I have  tried many different methods within Mathematica
> 3.0 and have not been  successful.  I would appreciate any suggestions
> as to how to accomplish this  task.
> Thank you.
> 
> Dr. Christopher J. Freitas
> Principal Engineer - Computational Mechanics Southwest Research
> Institute
> Voice: 210-522-2137, Fax: 210-522-3042

Here is the kind of data you have, right?:
a=Table[Random[Integer,{0,100}],{25}]
{3,9,42,55,38,10,28,40,3,13,52,80,87,21,30,14,43,9,64,42,76,30,53,5,19}

b=Table[Random[Integer,{0,100}],{25}]
{27,97,82,65,45,89,41,80,24,42,69,12,22,99,86,52,32,59,64,40,3,22,60,25,22}

First group the two lists into a list of lists. both={a,b}
{{3,9,42,55,38,10,28,40,3,13,52,80,87,21,30,14,43,9,64,42,76,30,53,5,19},{27,
   
97,82,65,45,89,41,80,24,42,69,12,22,99,86,52,32,59,64,40,3,22,60,25,22}}

both is essentially an array with two rows of 25 numbers each.  The
transpose 
of this array is an array with 25 rows, each with two numbers, the 
corresponding entries in a and b.

Transpose[both]
{{3,27},{9,97},{42,82},{55,65},{38,45},{10,89},{28,41},{40,80},{3,24},{13,
   
42},{52,69},{80,12},{87,22},{21,99},{30,86},{14,52},{43,32},{9,59},{64,
    64},{42,40},{76,3},{30,22},{53,60},{5,25},{19,22}}

Now it's easy to pick the maximum from each pair to get the desired
result.
Map[Apply[Max,#]&,Transpose[both]]
{27,97,82,65,45,89,41,80,24,42,69,80,87,99,86,52,43,59,64,42,76,30,60,25,22}

Ken Levasseur
Math. Sci.
UMass Lowell 
http://www.wolfram.com/training/companies/levasseur.html



  • Prev by Date: Re: ANNOUNCE: Math::ematica 1.105 - Perl talks to Mathematica talks to Perl
  • Next by Date: Forcing Mathematica 3.0 to display a superscript 1/2 rather than a square root sign
  • Prev by thread: Re: Sorting of Data Lists
  • Next by thread: Re: Sorting of Data Lists