# 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:** 3

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 15, 2018, 12:15am UTC](https://discourse.julialang.org/t/could-you-explain-what-are-views/17535/3 "2018-11-15T00:15:57Z")

</div>

In short, a “view” is a data structure that acts like an array (it is a subtype of `AbstractArray` in Julia), but the underlying data is actually part of another array.

For example, if `x` is an array and `v = @view x[1:10]`, then `v` acts like a 10-element array, but its data is actually accessing the first 10 elements of `x`. Writing to a view, e.g. `v[3] = 2`, writes directly to the underlying array `x` (in this case modifying `x[3]`).

Slicing operations like `x[1:10]` create a copy by default in Julia. `@view x[1:10]` changes it to make a view. The `@views` macro can be used on a whole block of code (e.g. `@views function foo() .... end` or `@views begin ... end` to change _all_ the slicing operations in that block to use views.

Sometimes making a copy of the data is faster and sometimes using a view is faster, as [described in the manual](https://docs.julialang.org/en/v1/manual/performance-tips/index.html#Consider-using-views-for-slices-1).

The “views” terminology is pretty standard; e.g. [similar terminology is used in NumPy](https://www.tutorialspoint.com/numpy/numpy_copies_and_views.htm) (which defaults to views for slices) and [Boost for C++](https://www.boost.org/doc/libs/1_63_0/libs/multi_array/doc/user.html#sec_views).

A pull request to improve the Julia documentation would be welcome. (Update: [https://github.com/JuliaLang/julia/pull/34390](https://github.com/JuliaLang/julia/pull/34390))

---

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