Mathematica 9 is now available
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: [mg124384] Re: Is there any efficient easy way to compare two lists with the same length with Mathematica?
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Wed, 18 Jan 2012 05:57:04 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

Over time more and more things like this have been extended to work 
automatically on lists. But so far, as you discovered, not GreaterEqual 
(nor Greater, etc.).  Here's one way without explicitly using Table:

   a = RandomInteger[{0, 20}, 5];
   b = RandomInteger[{0, 20}, 5];
   And @@ MapThread[Greater, {a, b}]

The key there is MapThread, which does what you (and I) would evidently 
like Mathematica to do automatically -- in effect, to make GreaterEqual 
have Listable as an Attribute.

On 1/17/12 3:34 AM, 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}]
>
> Any better tricks to do this?
>

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305



  • Prev by Date: Win7 "not responding"; WinXP no problem w/ my Manipulate
  • Next by Date: Re: How to coerce a string pattern to an ordinary pattern?
  • 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?