# Question ) What is the difference between putting @. and . for every algebraic operator?

**URL:** https://discourse.julialang.org/t/question-what-is-the-difference-between-putting-and-for-every-algebraic-operator/65603
**Category:** General Usage
**Created:** [July 31, 2021, 3:19pm UTC](https://discourse.julialang.org/t/question-what-is-the-difference-between-putting-and-for-every-algebraic-operator/65603 "2021-07-31T15:19:57Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Zerosum](https://avatars.discourse-cdn.com/v4/letter/z/b2d939/32.png) [@Zerosum](https://discourse.julialang.org/u/Zerosum)
#### Post date: [July 31, 2021, 3:19pm UTC](https://discourse.julialang.org/t/question-what-is-the-difference-between-putting-and-for-every-algebraic-operator/65603/1 "2021-07-31T15:19:57Z")

</div>

I am not sure if I am using the macro @. well. I thought I can avoid putting . (elementwise calculation) for + , -, / and so on by using the macro. For my project, I used it several times, but sometimes it doesn’t work. I would like to know what I am missing.

For instance, I have a function with a multi-dimensional array input :

```julia
**for i in 1:length(x)**
**if x[i] < 0**
**x[i] = 0**
 **end**
 **end**
**return(x)**
 **end**

```

and

```julia
**z = max_op(y) .+ max_op( (indi_bel .- b .+ β .* δ .* max_op(y)) ./ (1-β*k) .- max_op(y))**
**return(z)**
 **end**

```

When I run these two functions, it runs perfectly. However when I use @. macro,

```julia
**function intern_A(y)**
**z = @. max_op(y) + max_op( (indi_bel - b + β * δ * max_op(y)) / (1-β*k) - max_op(y))**
**return(z)**
 **end**

```

the following error occurs: “methodError: no method matching setindex!(::Float64, ::Int64, ::Int64)”.

Is it because the type of the output of max\_op function is unsuitable for the macro?  
Any responses would be more than appreciated.

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [July 31, 2021, 3:36pm UTC](https://discourse.julialang.org/t/question-what-is-the-difference-between-putting-and-for-every-algebraic-operator/65603/2 "2021-07-31T15:36:30Z")

</div>

Welcome! Please quote your code by surrounding it with triple backticks (```) to make it easier to read.

> [@Zerosum](#):
>
> the following error occurs: “methodError: no method matching setindex!(::Float64, ::Int64, ::Int64)”.

When you use `z = @. max_op(y) + ...`, `max_op` also receives a dot. It’s the same as if you had written

```julia
z = max_op.(y) .+ max_op.(...)

```

So in `max_op`, `x[i] = 0` fails because you can’t index into a Float to set a value. After all, it’s already a scalar.

---

<div class="post-metadata">

### Author: ![Zerosum](https://avatars.discourse-cdn.com/v4/letter/z/b2d939/32.png) [@Zerosum](https://discourse.julialang.org/u/Zerosum)
#### Post date: [July 31, 2021, 3:45pm UTC](https://discourse.julialang.org/t/question-what-is-the-difference-between-putting-and-for-every-algebraic-operator/65603/3 "2021-07-31T15:45:16Z")

</div>

Now I completely understand !  
Thank you very much !

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [July 31, 2021, 6:14pm UTC](https://discourse.julialang.org/t/question-what-is-the-difference-between-putting-and-for-every-algebraic-operator/65603/4 "2021-07-31T18:14:50Z")

</div>

> [@Sukera](#):
>
> It’s the same as if you had written
> 
> ```julia
> z = max_op.(y) + max_op.(...)
> 
> ```

You’re missing a dot, it’s the same as

```julia
z = max_op.(y) .+ max_op.(...)

```

and all other function calls inside `max_op` are dotted as well. `@.` is useful when you want to broadcast _all_ the function calls in the expression you apply it to. A typical case where you don’t want to use `@.` is when you a matrix multiplication `A * B`: `@. A * B` would turn it into an element-wise product, if possible

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [July 31, 2021, 6:22pm UTC](https://discourse.julialang.org/t/question-what-is-the-difference-between-putting-and-for-every-algebraic-operator/65603/5 "2021-07-31T18:22:26Z")

</div>

> [@giordano](#):
>
> You’re missing a dot, it’s the same as

Whoops! Yes of course, my bad.

> [@giordano](#):
>
> and all other function calls inside `max_op` are dotted as well.

Yes, inside the brackets after `max_op`, but not inside the function `max_op` itself - important distinction!

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [July 31, 2021, 7:42pm UTC](https://discourse.julialang.org/t/question-what-is-the-difference-between-putting-and-for-every-algebraic-operator/65603/6 "2021-07-31T19:42:17Z")

</div>

> [@Sukera](#):
>
> Whoops! Yes of course, my bad.

Since it’s marked as the solution, maybe you can edit the answer?

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [July 31, 2021, 8:00pm UTC](https://discourse.julialang.org/t/question-what-is-the-difference-between-putting-and-for-every-algebraic-operator/65603/7 "2021-07-31T20:00:26Z")

</div>

Done! Must have missed it before.
