@. Operator


Consider the following code:

a = 10
b = 1:10  


c = a .= b

works just fine. But I have more complex expressions and do not wish to spend my time adding dots everywhere. So I tried:

@. D = a + b

However, this produces the error that D is not defined. Why is that? I would expect D to be a vector.

ERROR: UndefVarError: D not defined
[1] top-level scope at none:0

1 Like

c = a .= b doesn’t work, but I suspect you meant c = a .+ b, which does.

However, @. D = a + b is the same as D .= a .+ b which tries to do an in-place assignment to D.

If you first do D = zeros(10), then @. D = a + b will work.


The syntax that would do what you expect is

D = @. a + b

which creates an array D instead of trying to do in-place assignment to an existing array.