# Indexing error?

**URL:** <https://discourse.julialang.org/t/indexing-error/69786>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 14, 2021, 10:38pm UTC](https://discourse.julialang.org/t/indexing-error/69786 "2021-10-14T22:38:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 14, 2021, 10:38pm UTC](https://discourse.julialang.org/t/indexing-error/69786/1 "2021-10-14T22:38:25Z")

</div>

X, Y, and E are longitude, latitude and elevation, respectively, on the same 86400 x 43200 grid. My goal is to reduce their resolution by 10 folder. Why does the below code keep throwing out the below error?

# my script:

```julia-auto
m = size(X);
Ind1 = [1:10:m[1]];
Ind2 = [1:10:m[2]];

X = X[Ind1, Ind2];
Y = Y[Ind1, Ind2];
E = E[Ind1, Ind2];

```

# Error message:

```julia-auto
**ERROR:** LoadError: ArgumentError: invalid index: StepRange{Int64, Int64}[1:10:86391] of type Vector{StepRange{Int64, Int64}}

Stacktrace:
[1] **to_index(** I::Vector{StepRange{Int64, Int64}} **)**
@ Base ./indices.jl:297
[2] **to_index(** A::Matrix{Float64}, i::Vector{StepRange{Int64, Int64}} **)**
@ Base ./indices.jl:277
[3] **to_indices**
@ ./indices.jl:333 [inlined]
[4] **to_indices**
@ ./indices.jl:324 [inlined]
[5] **getindex(** ::Matrix{Float64}, ::Vector{StepRange{Int64, Int64}}, ::Vector{StepRange{Int64, Int64}} **)**
@ Base ./abstractarray.jl:1170
[6] top-level scope
in expression starting at test.jl:35

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 14, 2021, 10:42pm UTC](https://discourse.julialang.org/t/indexing-error/69786/2 "2021-10-14T22:42:18Z")

</div>

> [@leon](#):
>
> `Ind1 = [1:10:m[1]];`

This is a vector that contains one element, which is a range.

Remove the braces. That should work.

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 14, 2021, 10:47pm UTC](https://discourse.julialang.org/t/indexing-error/69786/3 "2021-10-14T22:47:59Z")

</div>

Thank you so much! I didn’t know it’s that easy of a fix.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 14, 2021, 10:51pm UTC](https://discourse.julialang.org/t/indexing-error/69786/4 "2021-10-14T22:51:23Z")

</div>

If you wanted an actual vector of indexes (which you don’t in this case), you would do:

```julia
Ind1 = collect(1:10:m[1])

```

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 14, 2021, 11:05pm UTC](https://discourse.julialang.org/t/indexing-error/69786/5 "2021-10-14T23:05:33Z")

</div>

Thank you for sharing!

So these three things are all different from each other?  
A1 = 1:10:100;  
A2 = (1:10:100);  
A3 = [1:10:100];

---

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [October 14, 2021, 11:32pm UTC](https://discourse.julialang.org/t/indexing-error/69786/6 "2021-10-14T23:32:02Z")

</div>

`A1` and `A2` are the same. `A3` is an `Array` with one element. Aside, if you had written `A2` as `(1:10:100,)` it would be a `Tuple` with one element.

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [October 15, 2021, 2:50am UTC](https://discourse.julialang.org/t/indexing-error/69786/7 "2021-10-15T02:50:49Z")

</div>

What you may be thinking of is this slightly confusing syntax, which saves a few letters over `collect` or `vcat`:

```julia
julia> [1:20:100;] # syntax for vcat(1:10:100)
5-element Vector{Int64}:
  1
 21
 41
 61
 81

```

Note also that rather than needing a name `m` for the size, something like `X[1:10:end, 1:10:end]` should figure this out for you.
