MathGroup Archive 2007

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

Search the Archive

Re: style question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79367] Re: [mg79315] style question
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Wed, 25 Jul 2007 02:19:09 -0400 (EDT)
  • References: <12122347.1185321306092.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

Below are a couple of alternatives, with timings.

k = 10^6;
m1 = RandomInteger[{1}, {k, 2, 2}];
m2 = RandomInteger[{1}, {k, 2, 2}];
Timing[
  matches = Thread[temporary[m1, m2]] /. temporary -> Equal;
  Count[matches, True]
  ]
Timing@Count[Equal @@@ Transpose@{m1, m2}, True]
equal = Boole@Equal@## &;
Timing[equal @@@ Transpose@{m1, m2} // Total]

{4.266, 62343}

{3.328, 62343}

{4.844, 62343}

Bobby

On Tue, 24 Jul 2007 05:08:18 -0500, Yaroslav Bulatov  
<yaroslavvb at gmail.com> wrote:

> What is the recommended way of counting the number of matches in two
> lists?
>
> The natural way would be to thread over Equal, but Equal will evaluate
> before Thread gets to it. The method below works, but somehow feels
> wrong
>
> m1 = RandomInteger[{1}, {10^5, 2, 2}];
> m2 = RandomInteger[{1}, {10^5, 2, 2}];
> matches = Thread[temporary[m1, m2]] /. temporary -> Equal;
> Count[matches, True]
>
>
>



-- 

DrMajorBob at bigfoot.com


  • Prev by Date: Slow Import of CSV files
  • Next by Date: Re: Bug in automatically generated InputForm when using AutoGeneratedPackage->True
  • Previous by thread: Re: style question
  • Next by thread: Re: style question