MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: HELP: How to do count to the SUB-LIST

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82133] Re: [mg82096] HELP: How to do count to the SUB-LIST
  • From: János <janos.lobb at yale.edu>
  • Date: Sat, 13 Oct 2007 03:45:44 -0400 (EDT)
  • References: <200710120651.CAA04299@smc.vnet.net>

On Oct 12, 2007, at 2:51 AM, zhen wrote:

> Hallo, everyone
>
> I am new to Mathematica, and I get one problem now, hope to get some
> help here
>
> I got a list like this:
>
> {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0},
> {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0},
> {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}}
>
> I need to get a list to show the number of non zero number in each sub
> list, as to say, I need to get a list like this:
>
> {0,3,3,4,10,9}
>
> Thanks alot!
>

As a newbie, I would go with the following pattern testing  /See 
Condition in the Help/:

In[3]:=
(Count[#1, x_ /;
      x > 0] & ) /@ lst
Out[3]=
{0, 3, 3, 4, 10, 9}

Where lst is your list.  Of course if you have negative values you 
have to adjust the test.

J=E1nos


----------------------------------------------
Trying to argue with a politician is like lifting up the head of a 
corpse.
(S. Lem: His Master Voice)



  • Prev by Date: Re: HELP: How to do count to the SUB-LIST
  • Next by Date: Re: HELP: How to do count to the SUB-LIST
  • Previous by thread: HELP: How to do count to the SUB-LIST
  • Next by thread: Re: HELP: How to do count to the SUB-LIST