# 2D array filled with consecutive integers

**URL:** <https://discourse.julialang.org/t/2d-array-filled-with-consecutive-integers/44738>\
**Category:** General Usage\
**Created:** [August 11, 2020, 9:43am UTC](https://discourse.julialang.org/t/2d-array-filled-with-consecutive-integers/44738 "2020-08-11T09:43:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [August 11, 2020, 9:43am UTC](https://discourse.julialang.org/t/2d-array-filled-with-consecutive-integers/44738/1 "2020-08-11T09:43:21Z")

</div>

I’m trying to learn my way around array API and I need a 2D array filled with consecutive integers for quick sanity tests. I used this array like object:

```julia
w, h = 4, 3
a = reshape(1:w*h, w, h)

```

but it doesn’t work in cases like this:

```julia
julia> v = view(a, 2, :)
3-element view(reshape(::UnitRange{Int64}, 4, 3), 2, :) with eltype Int64:
  2
  6
 10

julia> v[1] = 19
ERROR: indexed assignment fails for a reshaped range; consider calling collect

```

What is a better option?

---

<div class="post-metadata">

**Author:** ![laborg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laborg/32/5474_2.png) [@laborg](https://discourse.julialang.org/u/laborg)\
**Post date:** [August 11, 2020, 9:48am UTC](https://discourse.julialang.org/t/2d-array-filled-with-consecutive-integers/44738/2 "2020-08-11T09:48:43Z")

</div>

You might try the suggestion from the error message:

> consider calling collect

→

```julia
a = reshape(collect(1:w*h), w, h)

```
