# Question about Indexing with CartesianIndex

**URL:** https://discourse.julialang.org/t/question-about-indexing-with-cartesianindex/20827
**Category:** General Usage
**Created:** [February 15, 2019, 5:17pm UTC](https://discourse.julialang.org/t/question-about-indexing-with-cartesianindex/20827 "2019-02-15T17:17:56Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![weech](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weech/32/6717_2.png) [@weech](https://discourse.julialang.org/u/weech)
#### Post date: [February 15, 2019, 5:17pm UTC](https://discourse.julialang.org/t/question-about-indexing-with-cartesianindex/20827/1 "2019-02-15T17:17:57Z")

</div>

Let’s say you have an array `a = reshape(1:5*10*25, 5, 10, 25)`. Why does `all(a[CartesianIndex(1, 1), 1:end] .== a[CartesianIndex(1, 1), 1:10] .== a[1, 1, 1:10])` return `true`? I would expect that `a[CartesianIndex(1, 1), 1:end]` would return a vector of length 25 like `a[1, 1, 1:end]`. What is the reasoning behind this? It’s almost as if the `end` is picking up on the length of the second dimension when one would expect it to pick up on the length of the third dimension.

Edit: I just saw the big warning in the docs. Sort of wish this just threw an error instead of letting bugs happen, but it is what it is.

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [February 15, 2019, 7:22pm UTC](https://discourse.julialang.org/t/question-about-indexing-with-cartesianindex/20827/2 "2019-02-15T19:22:00Z")

</div>

> [@weech](#):
>
> Edit: I just saw the big warning in the docs. Sort of wish this just threw an error instead of letting bugs happen, but it is what it is.

Yup, that’s the answer. Unfortunately, the `end` calculation is based entirely upon how many `,`-separated elements there are in the `[]`… and it happens at the parser level _before_ we have any type information. It’s even trickier than it appears since we also support arrays of CartesianIndex, too.

We’ve considered a redesign that would allow us to do this better, but it’s not obviously a win, either. Sorry this caught you out. I hate traps like this and wish we could do better.
