Re: style question
- To: mathgroup at smc.vnet.net
- Subject: [mg79368] Re: style question
- From: Vince Virgilio <blueschi at gmail.com>
- Date: Wed, 25 Jul 2007 02:19:40 -0400 (EDT)
- References: <f84jp8$qmp$1@smc.vnet.net>
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