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

• To: mathgroup at smc.vnet.net
• Subject: [mg124385] Re: Is there any efficient easy way to compare two lists with the same length with Mathematica?
• From: Andy Ross <andyr at wolfram.com>
• Date: Wed, 18 Jan 2012 05:57:25 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com

```On 1/17/2012 2: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?
>

If the vectors are very long and there isn't a good reason to expect
that most false cases will occur early you might consider UnitStep.

a=RandomReal[{0,1},10^6];
b=a+1;
c=RandomReal[{0,1},10^6];

Out= {0.858011,True}

In:= Total[UnitStep[b-a]]==Length[b]//AbsoluteTiming
Out= {0.046801,True}

Out= {0.858011,False}

In:= Total[UnitStep[c-a]]==Length[c]//AbsoluteTiming
Out= {0.046801,False}

Andy Ross
Wolfram Research

```

• Prev by Date: Re: Is there any efficient easy way to compare two lists with the same length with Mathematica?
• Next by Date: Re: MatrixPower problem
• 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?