I noticed that when D has at least one floating numbers, this program will work:
D = [-0, 0, 1, 5, 0, 7.1, 0]
D[D .== 0] .= 0.0001;
But it will quit working when D is composed of integers entirely.
D = [-0, 0, 1, 5, 0, 7, 0]
D[D .== 0] .= 0.0001;
Error message:
InexactError: Int64(0.0001)
Stacktrace:
[1] Int64
@ ./float.jl:723 [inlined]
[2] convert
@ ./number.jl:7 [inlined]
[3] fill!(A::SubArray{Int64, 1, Vector{Int64}, Tuple{Vector{Int64}}, false}, x::Float64)
@ Base ./multidimensional.jl:1055
[4] copyto!
@ ./broadcast.jl:944 [inlined]
[5] materialize!
@ ./broadcast.jl:894 [inlined]
[6] materialize!(dest::SubArray{Int64, 1, Vector{Int64}, Tuple{Vector{Int64}}, false}, bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}, Nothing, typeof(identity), Tuple{Float64}})
@ Base.Broadcast ./broadcast.jl:891
[7] top-level scope
@ In[209]:2
[8] eval
@ ./boot.jl:360 [inlined]
[9] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1116
In reality, my D can be all integers or not. What should be the fix? Thanks!