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: [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


  • Prev by Date: Re: choose elements from list based on elements in different list
  • Next by Date: Intersection of 2D Surfaces in 3D
  • Previous by thread: Counting nonzeros
  • Next by thread: Re: Counting nonzeros