Mathematica 9 is now available
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: [mg86893] Re: Counting nonzeros
  • From: Peter Pein <petsie at dordos.net>
  • Date: Tue, 25 Mar 2008 01:17:31 -0500 (EST)
  • References: <fs7iml$gma$1@smc.vnet.net>

carlos 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


  • Prev by Date: Match Pairs of Numbers
  • Next by Date: Re: Counting nonzeros
  • Previous by thread: Re: Counting nonzeros
  • Next by thread: Re: Counting nonzeros