Re: How to do count for sub list?????

• To: mathgroup at smc.vnet.net
• Subject: [mg82138] Re: How to do count for sub list?????
• From: Szabolcs Horvát <szhorvat at gmail.com>
• Date: Sat, 13 Oct 2007 03:48:18 -0400 (EDT)
• References: <fen5rk\$4gi\$1@smc.vnet.net>

```wangzhen0829 at gmail.com wrote:
> Hallo, everyone
>
> I am new to Mathematica, and now I have a problem with it, hope to get
> some help from here.
>
> I have a
>
> {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {
>   0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {
>   0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {
>   0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}}
>
>
>
> I need to get a list which represent the number of NON-zero number in
> each sublist.
>
> I should get a list like:
>
> {0,0,1,1,0,0,1,1}
>
> Thank you!
>
>

In[5]:= (Count[1, x_ /; x != 0] & ) /@ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{0, 0, 0, 0, 1, 0, 0, 0, 0, 0}}

Out[5]= {0, 0, 2, 1, 0, 0, 1, 1}

The third list has two non-zero elements.

--
Szabolcs

```

• Prev by Date: Re: HELP: How to do count to the SUB-LIST
• Next by Date: Re: Unwanted resize of frontend window
• Previous by thread: Re: Re: How to do count for sub list?????
• Next by thread: Re: How to do count for sub list?????