# Get a view as type Array and not as type SubArray

**URL:** <https://discourse.julialang.org/t/get-a-view-as-type-array-and-not-as-type-subarray/5211>\
**Category:** General Usage\
**Created:** [August 3, 2017, 8:44pm UTC](https://discourse.julialang.org/t/get-a-view-as-type-array-and-not-as-type-subarray/5211 "2017-08-03T20:44:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thofma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thofma/32/1691_2.png) [@thofma](https://discourse.julialang.org/u/thofma)\
**Post date:** [August 3, 2017, 8:44pm UTC](https://discourse.julialang.org/t/get-a-view-as-type-array-and-not-as-type-subarray/5211/1 "2017-08-03T20:44:25Z")

</div>

I have an array `A` of type `Array{T, N}`. I want a view of `A` but for various reasons I don’t want to deal with `SubArray`. Is there a way to get a view of `A` a la `view(A, ...)` but not as a `SubArray` but as `Array{T, N}`? I don’t mind if it is not as fast as a `SubArray`.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [August 3, 2017, 9:04pm UTC](https://discourse.julialang.org/t/get-a-view-as-type-array-and-not-as-type-subarray/5211/2 "2017-08-03T21:04:46Z")

</div>

You can’t generalize the function of your view to take AbstractArray{T,N}?  
Why not take an actual slice instead of a view? Slicing returns an array.

---

<div class="post-metadata">

**Author:** ![thofma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thofma/32/1691_2.png) [@thofma](https://discourse.julialang.org/u/thofma)\
**Post date:** [August 4, 2017, 6:32am UTC](https://discourse.julialang.org/t/get-a-view-as-type-array-and-not-as-type-subarray/5211/3 "2017-08-04T06:32:57Z")

</div>

It is not about a function definition but about parametrized types. I don’t want another type parameter.

Slicing also returns a `SubArray` on julia 0.5 and an error for \>= 0.6.

I don’t think it is possible to do what I want, but I wanted to make sure I am not missing something obvious.

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [August 4, 2017, 6:56am UTC](https://discourse.julialang.org/t/get-a-view-as-type-array-and-not-as-type-subarray/5211/4 "2017-08-04T06:56:25Z")

</div>

Slicing as in

```julia
a = rand(5)
b = a[1 : 3] # an Array{Float64,1}

```

not as in the old [`Base.slice`](https://docs.julialang.org/en/release-0.4/stdlib/arrays/?highlight=slice#Base.slice).

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [August 4, 2017, 2:35pm UTC](https://discourse.julialang.org/t/get-a-view-as-type-array-and-not-as-type-subarray/5211/5 "2017-08-04T14:35:18Z")

</div>

I don’t think it’s possible since `Array` doesn’t support general strides (as far as I know).

If you are taking a view of rows contained in a single column, it is possible using pointer arithmetic, but a very bad idea. Much better to just add another templates variable.
