Re: Logical comparisons of items in a two lists

• To: mathgroup at smc.vnet.net
• Subject: [mg75472] Re: Logical comparisons of items in a two lists
• From: Ray Koopman <koopman at sfu.ca>
• Date: Wed, 2 May 2007 03:50:42 -0400 (EDT)
• References: <f16q2u\$7er\$1@smc.vnet.net>

```On May 1, 12:26 am, "actu... at mchsi.com" <actu... at mchsi.com> wrote:
> Hello:
>
> I have two lists of real numbers, a & b.  I want two compare
> individual items in one list to the corresponding items in the other
> list.  For example Is a[[1]] > b[[1]]. At the end of the comparisons,
> I want to count the "Trues".  I know how to do this use a "Table"
> statement and a "Count" statement.  Is there a quicker, more efficient
> way of counting the number of "Trues".
>
> Thanks
>
> Larry

If the comparison can be reduced to a sign check
then UnitStep is hard to beat.

{a,b} = Table[Random[],{2},{1*^5}];

Timing[Length@a - Total@UnitStep[b-a]]
Timing@Count[a-b, _?Positive]
Timing@Inner[Boole@Greater@##&, a, b]
Timing@Count[Transpose@{a,b}, _?(Greater@@#&)]

{0.06 Second,49958}
{0.23 Second,49958}
{0.25 Second,49958}
{0.38 Second,49958}
{0.64 Second,49958}

```

• Prev by Date: Re: Logical comparisons of items in a two lists
• Next by Date: A comparison and thanks
• Previous by thread: Re: Logical comparisons of items in a two lists
• Next by thread: Re: Logical comparisons of items in a two lists