Reshaping S would also work, and might be slightly more efficient (though not much).
Cheers, Kevin On Wednesday, August 27, 2014, Ivar Nesje <[email protected]> wrote: > This is because if the current Julia indexing rules. See #5949 > <https://github.com/JuliaLang/julia/issues/5949> for a discussion in a > closed issue about changing it. > > This looks ugly, but works > > *A[k,:,:] = squeeze(A[k,:,:],1) ./ S;* > Regards Ivar > > kl. 15:45:26 UTC+2 onsdag 27. august 2014 skrev David Smith følgende: >> >> 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 >> >
