How to assignment of single value to multiple indexes to an Array?

This code works in Julia 0.6, but not the latest Julia 0.7. Is there any alternative ways to do this?

seg = zeros(UInt32,(100,100,100))       
seg[48:52,48:52, 1:end ] = one(UInt32)  

I got errors as follows:

ERROR: MethodError: no method matching setindex_shape_check(::UInt32, ::Int64, ::Int64, ::Int64)      
Closest candidates are:                                                                               
  setindex_shape_check(::AbstractArray, ::Integer...) at indices.jl:154                               
  setindex_shape_check(::AbstractArray{#s57,1} where #s57, ::Integer, ::Integer) at indices.jl:196    
  setindex_shape_check(::AbstractArray{#s57,2} where #s57, ::Integer, ::Integer) at indices.jl:200    
 [1] macro expansion at ./multidimensional.jl:641 [inlined]                                           
 [2] _unsafe_setindex!(::IndexLinear, ::Array{UInt32,3}, ::UInt32, ::UnitRange{Int64}, ::UnitRange{Int
64}, ::UnitRange{Int64}) at ./multidimensional.jl:636                                                 
 [3] _setindex! at ./multidimensional.jl:631 [inlined]                                                
 [4] setindex!(::Array{UInt32,3}, ::UInt32, ::UnitRange{Int64}, ::UnitRange{Int64}, ::UnitRange{Int64}
) at ./abstractarray.jl:998                                                                           
 [5] top-level scope at none:0                                                                        

Julia 0.7 should give you a deprecation message with the replacement:

julia> seg[48:52,48:52, 1:end ] = one(UInt32)
ā”Œ Warning: using `A[I...] = x` to implicitly broadcast `x` across many locations is deprecated. Use `A[I...] .= x` instead.
ā”‚   caller = top-level scope at none:0
ā”” @ Core none:0
1 Like

thanks for the quick reply. It turns out that I was using Julia 1.0 rather than 0.7!

Just a friendly reminder for other people who come across issues like this in the future: PSA: use Julia 0.7 if you are upgrading

1 Like