# Question about Dot Notation and "$"

**URL:** <https://discourse.julialang.org/t/question-about-dot-notation-and/76141>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [February 10, 2022, 3:15am UTC](https://discourse.julialang.org/t/question-about-dot-notation-and/76141 "2022-02-10T03:15:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kuldeep](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kuldeep/32/33657_2.png) [@Kuldeep](https://discourse.julialang.org/u/Kuldeep)\
**Post date:** [February 10, 2022, 3:15am UTC](https://discourse.julialang.org/t/question-about-dot-notation-and/76141/1 "2022-02-10T03:15:56Z")

</div>

```julia

I=10;J=5;
P=zeros(I,J);

#Related to Q1
P.= @. 1e-2*ones(I,J)*1; #Option 1.1, Don't work
P.= 1e-2.*ones(I,J).*1; #Option1.2, works

#Related to Q2
P.= @. 1e-2*ones(I,J)*1; #Option 2.1, Don't work
P.= @. 1e-2*$ones(I,J)*1; #Option2.2, works

```

Q-1 What is the exact difference between options 1.1 and 1.2 ? Why does one work and other don’t ?

Q-2 What does “$” exactly do so that option 2.2 gives the relevant output?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [February 10, 2022, 3:31am UTC](https://discourse.julialang.org/t/question-about-dot-notation-and/76141/2 "2022-02-10T03:31:57Z")

</div>

> [@Kuldeep](#):
>
> Q-1 What is the exact difference between options 1.1 and 1.2 ? Why does one work and other don’t ?

`@.` adds a dot to _every_ function call in the expression. In the case of 1.1, that includes the function `ones`, which isn’t what you want. We can write out what the `@.` is producing by hand like this:

```julia
P .= 1e-2 .* ones.(I, J) .* 1 # doesn't work

```

This fails because it’s trying to assign the entire output of `ones` (a `I x J` matrix) to _each_ element of `P`. Or, other words, it’s trying to do:

```julia
for i in eachindex(P)
  P[i] = 1e-2 * ones(I, J) * 1
end

```

which doesn’t work.

> [@Kuldeep](#):
>
> Q-2 What does “$” exactly do so that option 2.2 gives the relevant output?

The `$` syntax within `@.` means “don’t add a dot to this particular function call”, so:

```julia
@. 1e-2 * $ones(I, J) * 1

```

is equivalent to:

```julia
1e-2 .* ones(I, J) .* 1

```

i.e. the same as Option 1.2.
