Re: Counting nonzeros
- To: mathgroup at smc.vnet.net
- Subject: [mg86889] Re: [mg86865] Counting nonzeros
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Tue, 25 Mar 2008 01:16:46 -0500 (EST)
- References: <200803240644.BAA17004@smc.vnet.net>
On 24 Mar 2008, at 07:44, carlos at Colorado.EDU wrote: > I want to count the # of NZ entries in an arbitrary multilevel list, > say exp, that contains only integers. Is this the easiest way: > > k = Length[Flatten[exp]]-Count[Flatten[exp],0] > In Mathematica 6 this: Total[Unitize[expr], Infinity] is both shorter and much faster. Andrzej Kozlowski
- References:
- Counting nonzeros
- From: carlos@Colorado.EDU
- Counting nonzeros