Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Logical comparisons of items in a two lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75458] Re: Logical comparisons of items in a two lists
  • From: dh <dh at metrohm.ch>
  • Date: Tue, 1 May 2007 05:40:47 -0400 (EDT)
  • References: <f16q2u$7er$1@smc.vnet.net>


Hi Larry,

what's wrong with Count? It is pretty efficient. However, you could 

speed up the creation of the list a bit by e.g.: Thread[list1 > list2] 

or you could use Compilation:

fun=Compile[{{v1,_Real,1},{v2,_Real,1}},Table[Boole[v1[[i]]<v2[[i]]],{i,1,Length[v1]}]];

Total@ fun[list1,list2]

hope this helps, Daniel



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

> 

> 




  • Prev by Date: Apparently inconsistent behaviour of Convert[#, 1] &
  • Next by Date: Re: Mathematica 6.0 is released!
  • Previous by thread: Re: Logical comparisons of items in a two lists
  • Next by thread: Re: Logical comparisons of items in a two lists