Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: How to quickly find number of non-zero elements in sparse matrix rows?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56900] Re: How to quickly find number of non-zero elements in sparse matrix rows?
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Mon, 9 May 2005 01:46:46 -0400 (EDT)
  • Organization: The University of Western Australia
  • References: <d5hum0$k03$1@smc.vnet.net> <d5j5ec$qdr$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <d5j5ec$qdr$1 at smc.vnet.net>,
 Paul Abbott <paul at physics.uwa.edu.au> wrote:

> For the full array, the following is quite reasonable:
>  
>   Most[Length /@ Split[ArrayRules[sa], #1[[1,1]]==#2[[1,1]]&]]; //Timing

Chris Chiasson <chris.chiasson at gmail.com> pointed out that my code does not work
if the array has all zero rows. This is easy to fix:

 {#[[1,1,1]],Length[#]}& /@ 
    Split[ArrayRules[sa], #1[[1,1]]==#2[[1,1]]& ] // Most

returns the row number and number of non-zero entries in sa.

Cheers,
Paul

-- 
Paul Abbott                                      Phone: +61 8 6488 2734
School of Physics, M013                            Fax: +61 8 6488 1014
The University of Western Australia         (CRICOS Provider No 00126G)    
AUSTRALIA                               http://physics.uwa.edu.au/~paul
        http://InternationalMathematicaSymposium.org/IMS2005/


  • Prev by Date: Re: Calling a MS-DOS command
  • Next by Date: Re: Calling a MS-DOS command
  • Previous by thread: Re: Re: Re: How to quickly find number of non-zero elements in sparse matrix rows?
  • Next by thread: Re: Re: How to quickly find number of non-zero elements in sparse matrix rows?