How can i remove all zeros type of 0.0 from matrix?
I need to build the second and third columns without zeros 0.0, and all I could come up with was to remove the zeros. I using CairoMakie for plot
Thank your for help
I’m not sure I understand what you’re after. You might need to provide an example of your desired output. But here are a couple of related options assuming your matrix is z
# for each column, return the nonzero values
julia> [filter(!iszero,c) for c in eachcol(z)]
3-element Vector{Vector{Float64}}:
[9.94549e-6, 1.01235e-5, 9.97805e-6, 9.61955e-6]
[1.0e-5, 2.78136e-5, 1.0e-5, 1.0e-5]
[-6.21704e-6, -6.45014e-6, -7.118e-6, -5.62205e-6]
# remove rows that are entirely zero
julia> permutedims(stack(filter(!iszero,eachrow(z))))
4×3 Matrix{Float64}:
9.94549e-6 1.0e-5 -6.21704e-6
1.01235e-5 2.78136e-5 -6.45014e-6
9.97805e-6 1.0e-5 -7.118e-6
9.61955e-6 1.0e-5 -5.62205e-6
# remove zeros from each column, then reassemble (assuming the shortened columns have the same lengths)
julia> reduce(hcat, [filter(!iszero, c) for c in eachcol(z)])
4×3 Matrix{Float64}:
9.94549e-6 1.0e-5 -6.21704e-6
1.01235e-5 2.78136e-5 -6.45014e-6
9.97805e-6 1.0e-5 -7.118e-6
9.61955e-6 1.0e-5 -5.62205e-6