Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Counting nonzeros

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86903] Re: Counting nonzeros
  • From: rfsdias at hotmail.com
  • Date: Wed, 26 Mar 2008 04:48:02 -0500 (EST)
  • References: <fs7iml$gma$1@smc.vnet.net> <fsa5gf$ae8$1@smc.vnet.net>

On 25 mar, 03:18, Peter Pein <pet... at dordos.net> wrote:
> car... at colorado.edu schrieb:
>
> > 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]
>
> Count[Flatten[exp],Except[0]] is a bit shorter
>
> Peter

try also: Count[exp,Except[0],-1]

regards
Robson


  • Prev by Date: Re: Possible values for the Method option for Graphics??
  • Next by Date: Re: Intersection of 2D Surfaces in 3D
  • Previous by thread: Re: Counting nonzeros
  • Next by thread: Re: Counting nonzeros