# Can't use tuple of \`UInt\` as index

**URL:** https://discourse.julialang.org/t/cant-use-tuple-of-uint-as-index/54968
**Category:** General Usage
**Tags:** indexing
**Created:** [February 10, 2021, 6:12am UTC](https://discourse.julialang.org/t/cant-use-tuple-of-uint-as-index/54968 "2021-02-10T06:12:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)
#### Post date: [February 10, 2021, 6:12am UTC](https://discourse.julialang.org/t/cant-use-tuple-of-uint-as-index/54968/1 "2021-02-10T06:12:04Z")

</div>

Is this expected behavior?

```julia
julia> idx = UInt(3); A = rand(4); A[idx]
0.10882052381690266

julia> idx = (UInt(3), UInt(1)); A = rand(4, 5); A[idx]
ERROR: ArgumentError: invalid index: (0x0000000000000003, 0x0000000000000001) of type Tuple{UInt64,UInt64}
Stacktrace:
 [1] to_index(::Tuple{UInt64,UInt64}) at .\indices.jl:297
 [2] to_index(::Array{Float64,2}, ::Tuple{UInt64,UInt64}) at .\indices.jl:274
 [3] to_indices at .\indices.jl:325 [inlined]
 [4] to_indices at .\indices.jl:322 [inlined]
 [5] getindex(::Array{Float64,2}, ::Tuple{UInt64,UInt64}) at .\abstractarray.jl:1060
 [6] top-level scope at none:1

```

I’m writing a function that I would like to work with with `UInt` or `Int` arrays as input, but this issue (and an analogous one when using `get(A, idx, 0)`) is getting in the way.

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [February 10, 2021, 6:39am UTC](https://discourse.julialang.org/t/cant-use-tuple-of-uint-as-index/54968/2 "2021-02-10T06:39:00Z")

</div>

You can either splat or use a CartesianIndex if you want to index a multidimensional array.

```julia
julia> A[idx...]
0.8201224060592813

julia> A[CartesianIndex(idx)]
0.8201224060592813

julia> get(A, CartesianIndex(idx), 0)
0.8201224060592813

```

---

<div class="post-metadata">

### Author: ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)
#### Post date: [February 10, 2021, 6:42am UTC](https://discourse.julialang.org/t/cant-use-tuple-of-uint-as-index/54968/3 "2021-02-10T06:42:11Z")

</div>

Splat doesn’t work in `get()`, but `CartesianIndex()` does. Thank you.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [February 10, 2021, 8:51am UTC](https://discourse.julialang.org/t/cant-use-tuple-of-uint-as-index/54968/4 "2021-02-10T08:51:33Z")

</div>

This has been solved, I just wanted to point out that it is unrelated to `UInt` vs `Int`. You simply cannot index with tuples like that, so the same thing will happen here:

```julia
jl> idx = (3, 1); A[idx]
ERROR: ArgumentError: invalid index: (3, 1) of type Tuple{Int64,Int64}

```

---

<div class="post-metadata">

### Author: ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)
#### Post date: [February 10, 2021, 8:58am UTC](https://discourse.julialang.org/t/cant-use-tuple-of-uint-as-index/54968/5 "2021-02-10T08:58:09Z")

</div>

You can use `get()` like that with no problem, hence my issue.
