# Int vector to CarthesianIndex

**URL:** <https://discourse.julialang.org/t/int-vector-to-carthesianindex/45417>\
**Category:** New to Julia\
**Created:** [August 23, 2020, 2:10pm UTC](https://discourse.julialang.org/t/int-vector-to-carthesianindex/45417 "2020-08-23T14:10:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Honza9723](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/honza9723/32/7807_2.png) [@Honza9723](https://discourse.julialang.org/u/Honza9723)\
**Post date:** [August 23, 2020, 2:10pm UTC](https://discourse.julialang.org/t/int-vector-to-carthesianindex/45417/1 "2020-08-23T14:10:58Z")

</div>

Dear all,

I would like to ask whether there is some way, how to transform a vector of Int64s to CarthesianIndex object.

Naive approach:

r = collect(1:5)  
CartesianIndex( r )

failed me, and I don’t know how to proceed further. Any advice/suggestion would be welcome!

Best,  
Honza

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [August 23, 2020, 2:13pm UTC](https://discourse.julialang.org/t/int-vector-to-carthesianindex/45417/2 "2020-08-23T14:13:52Z")

</div>

I’m assuming you want the cartesian index to look like `CartesianIndex(1,2,3,4,5)`. You can construct that with a tuple rather than a vector:

```julia
julia> CartesianIndex(Tuple(1:5))
CartesianIndex(1, 2, 3, 4, 5)

```

---

<div class="post-metadata">

**Author:** ![Honza9723](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/honza9723/32/7807_2.png) [@Honza9723](https://discourse.julialang.org/u/Honza9723)\
**Post date:** [August 23, 2020, 2:20pm UTC](https://discourse.julialang.org/t/int-vector-to-carthesianindex/45417/3 "2020-08-23T14:20:22Z")

</div>

Thank you, I found a workaround based on your suggestion.

Firstly transform Array into Tuple, and then to CartesianIndex.

rr = [1 5 6 7]  
aa = Tuple(Int64(x) for x in rr)  
tt = CartesianIndex(aa)

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [August 23, 2020, 2:50pm UTC](https://discourse.julialang.org/t/int-vector-to-carthesianindex/45417/4 "2020-08-23T14:50:02Z")

</div>

You can also use

```julia
r = collect(1:5)
CartesianIndex(r...)

```

Of course you don’t need the `collect` either, but I presume you’re converting more general arrays than what can be expressed by a `UnitRange`.
