Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: Is there any efficient easy way to compare two lists with the same length with Mathematica?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124380] Re: Is there any efficient easy way to compare two lists with the same length with Mathematica?
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Tue, 17 Jan 2012 07:01:49 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

On 1/17/12 at 3:34 AM, aoirex at gmail.com (Rex) wrote:

>Given two lists `A={a1,a2,a3,...an}` and `B={b1,b2,b3,...bn}`, I
>would say `A>=B` if and only if all `ai>=bi`.

>There is a built-in logical comparison of two lists, `A==B`, but no
>`A>B`. Do we need to compare each element like this

>And@@Table[A[[i]]>=B[[i]],{i,n}]

I think you do need to do an element by element comparison. But
you don't need to specifically select each element using Part as
you are doing. That is:

In[13]:= {a, b} = RandomInteger[100, {2, 5}];
And @@ Thread[a > b]

Out[14]= False

In[15]:= c = RandomInteger[{150, 200}, 5];
And @@ Thread[c > a]

Out[16]= True




  • Prev by Date: Re: Cross reference - a further question.
  • Next by Date: Re: determining coefficients of a polynomial
  • Previous by thread: Re: Is there any efficient easy way to compare two lists with the same length with Mathematica?
  • Next by thread: Re: Is there any efficient easy way to compare two lists with the same length with Mathematica?