Re: Logical comparisons of items in a two lists
- To: mathgroup at smc.vnet.net
- Subject: [mg75480] Re: [mg75446] Logical comparisons of items in a two lists
- From: Carl Woll <carlw at wolfram.com>
- Date: Wed, 2 May 2007 03:54:57 -0400 (EDT)
- References: <200705010722.DAA07278@smc.vnet.net>
actuary 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
>
>
>
I would do this using UnitStep. Here is some test data:
d1=Table[Random[],{10^6}];
d2=Table[Random[],{10^6}];
Here is the UnitStep approach:
Total[UnitStep[d1-d2]]//Timing
{0.203 Second,500735}
Here is an approach similar to using Table and Count:
Count[Thread[d1>d2],True]//Timing
{3.172 Second,500735}
Carl Woll
Wolfram Research
- References:
- Logical comparisons of items in a two lists
- From: "actuary@mchsi.com" <actuary@mchsi.com>
- Logical comparisons of items in a two lists