```@.``` throws unexpected error

@. affects every function call, which includes ones and rand in your example. The code is equivalent to:

y .= rand.(2, 2) .+ ones.(2, 2)

which roughly means: “for each index in y, do y[I] = rand(2,2) + ones(2, 2)” , which isn’t what you want.

In this case, you may want to just add the . to the functions you actually want to broadcast, as in:

y .= rand(2, 2) .+ ones(2, 2)
2 Likes