# Unexpected map! behaviour

**URL:** https://discourse.julialang.org/t/unexpected-map-behaviour/24920
**Category:** New to Julia
**Created:** [June 4, 2019, 3:25pm UTC](https://discourse.julialang.org/t/unexpected-map-behaviour/24920 "2019-06-04T15:25:50Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [June 4, 2019, 3:31pm UTC](https://discourse.julialang.org/t/unexpected-map-behaviour/24920/2 "2019-06-04T15:31:36Z")

</div>

In `map!(x ->x*2, a[1,:], [1,2,3])` you are not modifying `a`. `a[1, :]` returns a _new_ vector which you put the result in. It is equivalent to

```julia
a = zeros(2, 3)
tmp = a[1, :]
map!(x->x*2, tmp, [1, 2, 3])

```

so you are only modifying `tmp`. You can use a view if you want your output vector to point to the same memory as `a`, e.g.

```julia
map!(x->x*2, @view(a[1,:]), [1, 2, 3])

```

See also [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530)

---

_[View the full topic](https://discourse.julialang.org/t/unexpected-map-behaviour/24920)._
