# Could you explain what are views?

**URL:** <https://discourse.julialang.org/t/could-you-explain-what-are-views/17535>\
**Category:** New to Julia\
**Created:** [November 14, 2018, 11:06pm UTC](https://discourse.julialang.org/t/could-you-explain-what-are-views/17535 "2018-11-14T23:06:29Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [November 14, 2018, 11:52pm UTC](https://discourse.julialang.org/t/could-you-explain-what-are-views/17535/2 "2018-11-14T23:52:31Z")

</div>

Try and modify the result, and you’ll see the difference:

```julia
julia> A = [1 2; 3 4];
julia> B = A[:,:]; # This is actually a copy of A
julia> B[1,1]=0;
julia> A
2×2 Array{Int64,2}:
 1 2
 3 4

julia> B
2×2 Array{Int64,2}:
 0 2
 3 4

```

But:

```julia
julia> B = @view A[:,:]; # B is a view of A
julia> B[1,1]=0;
julia> A # Ooops!
2×2 Array{Int64,2}:
 0 2
 3 4

julia> B
2×2 view(::Array{Int64,2}, :, :) with eltype Int64:
 0 2
 3 4

```

In this particular case, it’s the same as `B = A`, so `@view` does not seem very useful. It makes more sense when you look at some slice, e.g. `B = @view A[1,:]` (a view of the first row).

That’s useful if you want to make some calculations based on the values of particular rows, columns or blocks of a matrix, without having to make a copy of that portion of the array (which takes more memory and time). Just take care with the changes, as in the example!

`@view` only applies to the slice next to the macro name; `@views` makes views to all the slices right to it.

---

_[View the full topic](https://discourse.julialang.org/t/could-you-explain-what-are-views/17535)._
