Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8006 > unrolled thread

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

Started byArmand Tamzarian <mike.honeychurch@gmail.com>
First post2012-01-19 10:17 +0000
Last post2012-01-19 10:17 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Is there any efficient easy way to compare two lists with the same length with Mathematica? Armand Tamzarian <mike.honeychurch@gmail.com> - 2012-01-19 10:17 +0000

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

FromArmand Tamzarian <mike.honeychurch@gmail.com>
Date2012-01-19 10:17 +0000
SubjectRe: Is there any efficient easy way to compare two lists with the same length with Mathematica?
Message-ID<jf8qk4$3p2$1@smc.vnet.net>
On Jan 18, 9:58 pm, Andy Ross <an...@wolfram.com> wrote:
> 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];
>
> In[311]:= And@@Thread[b>a]//AbsoluteTiming
> Out[311]= {0.858011,True}
>
> In[312]:= Total[UnitStep[b-a]]==Length[b]//AbsoluteTiming
> Out[312]= {0.046801,True}
>
> In[313]:= And@@Thread[c>a]//AbsoluteTiming
> Out[313]= {0.858011,False}
>
> In[314]:= Total[UnitStep[c-a]]==Length[c]//AbsoluteTiming
> Out[314]= {0.046801,False}
>
> Andy Ross
> Wolfram Research


Min[UnitStep[c - a]] == 1

and

Min[Sign[c - a]] == 1

are also pretty quick.

Mike

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web