Re: style question
- To: mathgroup at smc.vnet.net
- Subject: [mg79424] Re: style question
- From: Vince Virgilio <blueschi at gmail.com>
- Date: Thu, 26 Jul 2007 05:37:28 -0400 (EDT)
- References: <f84jp8$qmp$1@smc.vnet.net><f86rat$pfm$1@smc.vnet.net>
On Jul 25, 2:41 am, Vince Virgilio <blues... at gmail.com> wrote: > On Jul 24, 6:20 am, Yaroslav Bulatov <yarosla... 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] > > MapThread should avoid eager evaluation of Equal. I am away from > Mathematica, so cannot test this: > > matches = MapThread[Equal, {m1, m2}]; > > (I wonder if MapThread was created specifically to mitigate evaluation > issues.) > > Vince Virgilio Correction to self. I overlooked the three-dimensionality of m1 and m2. Again I'm without Mathematica; still you might try: matches = MapThread[Equal, {m1, m2}, 3]; Count[matches, True, {3}] By the way, your syntax for the first argument of RandomInteger appears to be undocumented. Vince Virgilio