MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Logical comparisons of items in a two lists

actuary at 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

Hi Larry,

Since you show neither your code (or a similar example) nor any timing,
it is hard to tell where the bottleneck is located, although I would bet 
on the *Table* part.

In the code below, we compare two lists of 10,000,000 real numbers 
(machine precision) each. Comparing the pairs of elements with *Table* 
took nearly twice the time needed by *MapThread*. (Note that the 
difference is less dramatic for smaller values of n.) Moreover, you can 
see that the built-in function *Count* is highly efficient: it took less 
than 0.8 second to count all the *True* values.


{30.563 Second,Null}

{18.766 Second,Null}

{0.797 Second,4998689}

Of course, you may have done something completely different, by I could 
not read your mind!

Best regards,

  • Prev by Date: Re: Simplification
  • Next by Date: exceptional group symmetry breaking as a binary entropy process
  • Previous by thread: Re: Logical comparisons of items in a two lists
  • Next by thread: Re: Logical comparisons of items in a two lists