For example, I have an array
julia> a = ones(2, 3)
2×3 Array{Float64,2}:
1.0 1.0 1.0
1.0 1.0 1.0
Now I want to fill its first row to be all 3.0
,
julia> fill!(a[1,:],3)
3-element Array{Float64,1}:
3.0
3.0
3.0
After this, my a
is still not changed. I found this is because the source code only returns a new array, rather than actually fill
s an array.
function fill!(A::AbstractArray{T}, x) where T
xT = convert(T, x)
for I in eachindex(A)
@inbounds A[I] = xT
end
A
end
What should I do to achieve my goal?