On 10 October 2014 17:07, JVaz <[email protected]> wrote:
>
> I have a sparse vector, is there any function that returns an array with the
> index of its nonzero entires?
>
> E.g I have
>
> A
>
> 1048576x1 sparse matrix with 2 Float64 entries:
> [1      ,       1]  =  0.5
> [32801  ,       1]  =  0.5
>
>
> I want a function(A) --> [1,32801]

The following should hold.

    A = sparse(zeros(4711))
    idxs = rand(1:length(A), 17)
    A[idxs] = rand(17)
    @assert findnz(A)[1] == sort(idxs)

A reference for the function.

    http://julia.readthedocs.org/en/release-0.3/stdlib/base/#Base.findnz

> (I thought this wold be basic, but I couldn't find info in the documentation
> or the forums, sorry if I missed it)

No worries, what I usually do is use the page I linked and do a few
text searches.

    Pontus

Reply via email to