Re: Count using pattern on two different matrices

• To: mathgroup at smc.vnet.net
• Subject: [mg57084] Re: [mg57079] Count using pattern on two different matrices
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Sun, 15 May 2005 03:03:38 -0400 (EDT)
• References: <200505140858.EAA09500@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```On 14 May 2005, at 17:58, Lee Newman wrote:

> 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
>
>
Here is one way:

l1 = {{True, False}, {False, True}, {False, False}} ;
l2 = {{True, False, False}, {True, True, True}, {False, True, False}} ;

Count[Transpose[{l1, l2}],
_?(#1[[1,2]] == False && #1[[2,3]] == True & )]

0

Changing the criterion to L1[[row,2 ]]==False and L2[[row,3]]==False

Count[Transpose[{l1, l2}],
_?(#1[[1,2]] == False && #1[[2,3]] == False & )]

2

Andrzej Kozlowski

```

• Prev by Date: Re: Taking the Log causing Mathematica kernel crash.
• Next by Date: Re: Intersection of coordinate axes in origin (3d plot)
• Previous by thread: Re: Count using pattern on two different matrices
• Next by thread: Re: Count using pattern on two different matrices