# Taking a matrix and creating a 2Tuple with first element Row number, and second element row?

**URL:** https://discourse.julialang.org/t/taking-a-matrix-and-creating-a-2tuple-with-first-element-row-number-and-second-element-row/81934
**Category:** General Usage
**Created:** [May 30, 2022, 10:08pm UTC](https://discourse.julialang.org/t/taking-a-matrix-and-creating-a-2tuple-with-first-element-row-number-and-second-element-row/81934 "2022-05-30T22:08:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Alejandro\_Quiaro\_San](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alejandro_quiaro_san/32/35437_2.png) [@Alejandro\_Quiaro\_San](https://discourse.julialang.org/u/Alejandro_Quiaro_San)
#### Post date: [May 30, 2022, 10:08pm UTC](https://discourse.julialang.org/t/taking-a-matrix-and-creating-a-2tuple-with-first-element-row-number-and-second-element-row/81934/1 "2022-05-30T22:08:47Z")

</div>

Hello guys, I hope you are doing fine.

I would like to take a matrix and create a Tuple, where the first element is the row number (an index) and the second element is the row (a vector).

```julia
graph =[0 2 4 0 0 0; 0 0 1 7 0 0; 0 0 0 0 3 0;
        0 0 0 0 0 1; 0 0 0 2 0 5; 0 0 0 0 0 0];

```

I would like to get a tuple in the following way:

```julia
6-element Tuple
(1,[0 2 4 0 0 0])
(2,[0 0 1 7 0 0])
(3,[0 0 0 0 3 0])
(4,[0 0 0 0 0 1])
(5,[0 0 0 2 0 5])
(6,[0 0 0 0 0 0])

```

With a vector it is easy because

```julia
f=collect(enumerate(graph[1,:]))

```

returns an f=  
(1,0)  
(2,2)  
(3,4)  
(4,0)  
(5,0)  
(6,0)

How can I create a Tuple with the rows of the Matrix as second element? Any thoughts?

Thanks in advance.

---

<div class="post-metadata">

### Author: ![dylanxyz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanxyz/32/36646_2.png) [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)
#### Post date: [May 30, 2022, 10:58pm UTC](https://discourse.julialang.org/t/taking-a-matrix-and-creating-a-2tuple-with-first-element-row-number-and-second-element-row/81934/2 "2022-05-30T22:58:45Z")

</div>

This solves your problem?

```julia
julia> result = collect(enumerate(eachrow(graph)))
6-element Vector{Tuple{Int64, SubArray{Int64, 1, Matrix{Int64}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}}, true}}}:
 (1, [0, 2, 4, 0, 0, 0])
 (2, [0, 0, 1, 7, 0, 0])
 (3, [0, 0, 0, 0, 3, 0])
 (4, [0, 0, 0, 0, 0, 1])
 (5, [0, 0, 0, 2, 0, 5])
 (6, [0, 0, 0, 0, 0, 0])

```

---

<div class="post-metadata">

### Author: ![Alejandro\_Quiaro\_San](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alejandro_quiaro_san/32/35437_2.png) [@Alejandro\_Quiaro\_San](https://discourse.julialang.org/u/Alejandro_Quiaro_San)
#### Post date: [May 30, 2022, 11:05pm UTC](https://discourse.julialang.org/t/taking-a-matrix-and-creating-a-2tuple-with-first-element-row-number-and-second-element-row/81934/3 "2022-05-30T23:05:33Z")

</div>

Thank you so much! It works perfectly!
