MathGroup Archive 2010

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

Search the Archive

Re: Mathematica SparseArray Access Non-Default Values

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108379] Re: Mathematica SparseArray Access Non-Default Values
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Mon, 15 Mar 2010 05:02:58 -0500 (EST)
  • References: <hnkf9j$pnd$1@smc.vnet.net>

On Mar 14, 10:06 pm, wima <t... at gmx.de> wrote:
> Hi,
>
> I am currently dealing with really huge (~ 80,000 x 80,000) sparse
> matrices. I this context I need to read the number of non-default
> values in each row.
> When Accessing the i-th row of a SparseArray, this information is
> given.  E.g.
> test = SparseArray[{{1, 1} -> 3, {1, 5} -> 2, {5, 3} -> 1}];
> test[[1]]
> returns SparseArray[<2>, {5}]
> However, I fail to access the number of entries (here 2) to assign
> it to a variable.
> I did not find any information in the documentation so far.
> Does anyone have an idea?
>
> Thx

If s is a sparse array then

  s /. SparseArray[_,_,_,d_] :> Differences@d[[2,1]]

will return a list of the number of non-default values in each row.


  • Prev by Date: Re: character repeat
  • Next by Date: Re: windows 64 vs 32 bit
  • Previous by thread: Mathematica SparseArray Access Non-Default Values
  • Next by thread: Re: Mathematica SparseArray Access Non-Default Values