X[:, 3] doesn't produce a SubArray. It produces a brand new array.

-- John

On Nov 21, 2014, at 10:30 AM, Ján Dolinský <[email protected]> wrote:

> Hello,
> 
> I wanted an inplace function to write a result into a subarray as follows:
> 
> X = zeros(10,5)
> fill!(X[:,3], 0.1)
> 
> The X[:,3] is however not updated.
> 
> X[:,3] = fill(0.1, 10) does the update as expected.
> 
> Is this a desired behaviour ?
> 
> 
> ---
> 
> Alternatively, I can do
> 
> r = view(X,:,3)
> fill!(r, 0.1)
> 
> This results in an updated column of X
> 
> I wonder which is likely to be more efficient if used in a loop:
> 
> X[:,3] = fill(0.1, 10)
> 
> or 
> r = view(X,:,3)
> fill!(r, 0.1)
> 
> 
> Thanks,
> Jan

Reply via email to