       Re: Count using pattern on two different matrices

• To: mathgroup at smc.vnet.net
• Subject: [mg57092] Re: Count using pattern on two different matrices
• Date: Sun, 15 May 2005 03:03:46 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```On 5/14/05 at 4:58 AM, leenewm at umich.edu (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

One way to accomplish what you want would be

In:=
L1 = {{True, False},{False, True}, {False, False}};
L2 = {{True, False, False}, {True, True, True},
{False, True, False}};

In:=
Count[Equal@@@Transpose@{L1[[All, 2]], L2[[All, 3]]}, False]

Out=
0

Checking we see

In:=
L1[[All,2]]

Out=
{False, True, False}

and

In:=
L2[[All,3]]

Out=
{False,True,False}

Clearly, both are the same verifying the count above is correct.

An alternative to In using MapThread to do the same task would be:

In:=
Count[MapThread[#1 == #2 &, {L1[[All, 2]], L2[[All, 3]]}], False]

Out=
0
--
To reply via email subtract one hundred and four

```

• Prev by Date: Re: DSolve and K\$31, i am puzzled
• Next by Date: Re: InterpolatingFunctionAnatomy.m
• Previous by thread: Re: Count using pattern on two different matrices
• Next by thread: Re: Triangularize Matrix for Newmark method Keff=L^TDL