# How to convert CartesianIndex to integer

**URL:** <https://discourse.julialang.org/t/how-to-convert-cartesianindex-to-integer/38017>\
**Category:** General Usage\
**Created:** [April 22, 2020, 9:13am UTC](https://discourse.julialang.org/t/how-to-convert-cartesianindex-to-integer/38017 "2020-04-22T09:13:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hmemy](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@hmemy](https://discourse.julialang.org/u/hmemy)\
**Post date:** [April 22, 2020, 9:13am UTC](https://discourse.julialang.org/t/how-to-convert-cartesianindex-to-integer/38017/1 "2020-04-22T09:13:42Z")

</div>

Hi,

I am using findall function to create an array. but the results are in CartesianIndex as shown below.

```julia
A = findall(x->x>0, test)

```

**This results in**  
5-element Array{CartesianIndex{2},1}:  
CartesianIndex(1, 3)  
CartesianIndex(1, 4)  
CartesianIndex(1, 5)  
CartesianIndex(1, 6)  
CartesianIndex(1, 8)

How can I convert CartesianIndex to integer printing only the 2nd output like:  
3,4,5,6,8

Thank you.

---

<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:** [April 22, 2020, 9:18am UTC](https://discourse.julialang.org/t/how-to-convert-cartesianindex-to-integer/38017/2 "2020-04-22T09:18:12Z")

</div>

`[I[2] for I in A]`. But maybe the problem is that `test` is a matrix when you really want it to be a vector? Try `findall(x->x>0, vec(test))`.

---

<div class="post-metadata">

**Author:** ![hmemy](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@hmemy](https://discourse.julialang.org/u/hmemy)\
**Post date:** [April 22, 2020, 9:30am UTC](https://discourse.julialang.org/t/how-to-convert-cartesianindex-to-integer/38017/3 "2020-04-22T09:30:54Z")

</div>

> [@tim.holy](#):
>
> findall(x-\>x\>0, vec(test))

Using **vec** solved the problem.

Thank you.
