From: wima on 15 Mar 2010 01:06 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
From: Ray Koopman on 15 Mar 2010 06:03 On Mar 14, 10:06 pm, wima <t...(a)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.
From: Raffy on 15 Mar 2010 06:07 On Mar 14, 10:06 pm, wima <t...(a)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 SparseArray has some interesting behavior since it needs to work like a List and be accessed by Part, etc... You can see the internals of SparseArray with: sparseArray /. HoldPattern[SparseArray[x___]] :> {x} You can get the number of non-default values by doing: sparseArray /. SparseArray[_, _, _, x_] :> Length(a)Last[x]
From: Bob Hanlon on 15 Mar 2010 08:05 test = SparseArray[{ {1, 1} -> 3, {1, 5} -> 2, {5, 3} -> 1}]; Count[ArrayRules[test], {1, _} -> _] 2 Count[ArrayRules[test], {1, _}, 2] 2 Bob Hanlon ---- wima <tba2(a)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
|
Pages: 1 Prev: A module for some digital image processing-related tasks Next: Butterworth filter |