Re: How to do count for sub list?????
- To: mathgroup at smc.vnet.net
- Subject: [mg82160] Re: [mg82095] How to do count for sub list?????
- From: "Ricardo Samad" <resamad at gmail.com>
- Date: Sat, 13 Oct 2007 03:59:38 -0400 (EDT)
- References: <200710120650.CAA04282@smc.vnet.net>
Hi, name your list: l = {{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}}; and use Table[Length[l[[n]]] - Length[Position[l[[n]], 0]], {n, 1, Length[l]}] or Length[#] - Length[Position[#, 0]] & /@ l By the way, the result is {0, 0, 2, 1, 0, 0, 1, 1} and not {0,0,1,1,0,0,1,1= } as written in your e-mail. Ricardo On 10/12/07, wangzhen0829 at gmail.com <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! > > > -- ____________________________________ Ricardo Elgul Samad tel: (+55 11) 3133-9372 fax: (+55 11) 3133-9374 Centro de Lasers e Aplica=E7=F5es IPEN/CNEN-SP AV. Prof. Lineu Prestes 2242 Cidade Universit=E1ria 05508-000 S=E3o Paulo - SP Brazil ____________________________________
- References:
- How to do count for sub list?????
- From: wangzhen0829@gmail.com
- How to do count for sub list?????