Can anyone tell my why the code below fails?

Why is the error reporting an incorrect size for the right-hand side?

Is this a gotcha of the broadcast rules?

Is the only solution to boost S to a 1 x n x n array?

I prefer to avoid looping, if possible.

Thanks!


function f(n)
    A = rand(3,n,n); 
    S = rand(n,n); 
    for k = 1:size(A,1) 
        A[k,:,:] = A[k,:,:] ./ S; 
    end 
    return A 
end

julia> f(10)
ERROR: DimensionMismatch("tried to assign 10x10x10 array to 1x10x10 
destination")
in throw_setindex_mismatch at operators.jl:233
in setindex_shape_check at operators.jl:258
in setindex! at multidimensional.jl:72
in f at none:5

Reply via email to