Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove explicit zero values from sparse matrix in Julia

Tags:

julia

Is it possible to remove explicit zero value from sparse matrix in Julia?

Namely, I want to convert a=sparse([1],[1],[0]) into b=spzeros(1,1)

like image 288
sholi Avatar asked Dec 18 '22 06:12

sholi


1 Answers

Yes: see dropzeros:

julia> a=sparse([1],[1],[0])
1×1 SparseMatrixCSC{Int64,Int64} with 1 stored entry:
  [1, 1]  =  0

julia> dropzeros(a)
1×1 SparseMatrixCSC{Int64,Int64} with 0 stored entries

Or you can do it in place (modifying a) with dropzeros!.

like image 175
mbauman Avatar answered Jan 07 '23 12:01

mbauman