       Re: Count using pattern on two different matrices

• To: mathgroup at smc.vnet.net
• Subject: [mg57088] Re: [mg57079] Count using pattern on two different matrices
• From: "David Park" <djmp at earthlink.net>
• Date: Sun, 15 May 2005 03:03:42 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Lee,

First, generating a test case...

genrandombool := If[Random[Integer, {0, 1}] == 0, False, True]

L1 = Table[genrandombool, {3}, {2}]
L2 = Table[genrandombool, {3}, {3}]
{{True, False}, {False, True}, {True, False}}
{{True, False, True}, {False, True, True}, {False, False, True}}

Plus @@ MapThread[If[! Part[#1, 2] && Part[#2, 3], 1, 0] &, {L1, L2}]
2

David Park

From: Lee Newman [mailto:leenewm at umich.edu]
To: mathgroup at smc.vnet.net

I have two matrices with an equal number of rows, but not necessarily
columns, for example:

L1= {{True,False},{False, True},{False, False}, etc.....} ;
L2= {{True,False,False},{True, True,True},{False, True,False}, etc.....} ;

I would like to compute a count of the number of rows in which one of
the columns of L1 meets some criterion, and one of the columns of L2
meets some criterion, i.e.  If L1[[row,2 ]]==False  and
L2[[row,3]]==True  then this row contributes 1 to the count.

I suspect that there is an elegant way to do this, perhaps using Count[]
and MapThread, but I can't figure it out other than resorting to a
rather clumsy For or Do loop that would check line by line and maintain
a counter.

Any help would be appreciated,
Lee

```

• Prev by Date: Re: Count using pattern on two different matrices
• Next by Date: Re: Taking the Log causing Mathematica kernel crash.
• Previous by thread: Re: Count using pattern on two different matrices
• Next by thread: Re: Count using pattern on two different matrices