Re: style question
- To: mathgroup at smc.vnet.net
- Subject: [mg79330] Re: [mg79315] style question
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Wed, 25 Jul 2007 01:59:33 -0400 (EDT)
- References: <200707241008.GAA26147@smc.vnet.net>
On Jul 24, 2007, at 6:08 AM, Yaroslav Bulatov 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 > I'm not sure what you're trying to accomplish with these two statements: > m1 = RandomInteger[{1}, {10^5, 2, 2}]; > m2 = RandomInteger[{1}, {10^5, 2, 2}]; Do you mean m1=RandomInteger[{1,10^5},{2,2}] m2=RandomInteger[{1,10^5},{2,2}] ? If that's the case m1 and m2 will be matrices and if you want to do element by element comparison you should flatten them before applying Equal. As for your second problem, just use MapThread: Count[MapThread[Equal,{Flatten[m1],Flatten[m2]}],True] Regards, Ssezi
- References:
- style question
- From: Yaroslav Bulatov <yaroslavvb@gmail.com>
- style question