[julia-users] Is there an inverse of `sparse`?

2014-09-18 Thread DumpsterDoofus
Given column vectors I, J, and V, one can construct a sparse matrix using 
the following syntax:

sparse(I, J, V)

How about the reverse? I.e., given a sparse matrix S, is there a function 
which returns the column vectors I, J, and V that define S?

One can obtain the list of nonzero values V with the command

nonzeros(S)

but I'm not sure how to get the row and column coordinates I and J that go 
along with V. Is there a convenient way to obtain I and J?


Re: [julia-users] Is there an inverse of `sparse`?

2014-09-18 Thread John Myles White
Try findnz.

This seems to not be documented in the sparse section of the manual, but I 
would think it should be.

 — John

On Sep 18, 2014, at 6:58 PM, DumpsterDoofus peter.richter@gmail.com wrote:

 Given column vectors I, J, and V, one can construct a sparse matrix using the 
 following syntax:
 
 sparse(I, J, V)
 
 How about the reverse? I.e., given a sparse matrix S, is there a function 
 which returns the column vectors I, J, and V that define S?
 
 One can obtain the list of nonzero values V with the command
 
 nonzeros(S)
 
 but I'm not sure how to get the row and column coordinates I and J that go 
 along with V. Is there a convenient way to obtain I and J?



Re: [julia-users] Is there an inverse of `sparse`?

2014-09-18 Thread DumpsterDoofus


 Thanks, that's what I was looking for! I forked a copy of the 
 documentation on my GitHub account and added in the following entry to the 
 sparse matrix section:


.. function:: findnz(A)

   Returns a tuple (I, J, V) containing the column indices, row indices, and 
nonzero values. The I, J, and V satisfy ``S[I[k], J[k]] = V[k]``. Essentially 
the inverse of ``sparse``.


 


Re: [julia-users] Is there an inverse of `sparse`?

2014-09-18 Thread John Myles White
Submit a pull request?

One point: I think you may have flipped column indices and row indices in your 
description.

 — John

On Sep 18, 2014, at 7:45 PM, DumpsterDoofus peter.richter@gmail.com wrote:

 Thanks, that's what I was looking for! I forked a copy of the documentation 
 on my GitHub account and added in the following entry to the sparse matrix 
 section:
 
 .. function:: findnz(A)
 
Returns a tuple (I, J, V) containing the column indices, row indices, and 
 nonzero values. The I, J, and V satisfy ``S[I[k], J[k]] = V[k]``. Essentially 
 the inverse of ``sparse``.