# Matrix to row vector

**URL:** https://discourse.julialang.org/t/matrix-to-row-vector/90417
**Category:** New to Julia
**Created:** [November 17, 2022, 9:09pm UTC](https://discourse.julialang.org/t/matrix-to-row-vector/90417 "2022-11-17T21:09:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Muhammad\_Nadeem](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@Muhammad\_Nadeem](https://discourse.julialang.org/u/Muhammad_Nadeem)
#### Post date: [November 17, 2022, 9:09pm UTC](https://discourse.julialang.org/t/matrix-to-row-vector/90417/1 "2022-11-17T21:09:01Z")

</div>

Hello all,

I have two matrices

```julia
A = [1 1 1; 1 1 1; 1 1 1]
B = [1; 2; 3]

```

I want to multiply both of them row by row, meaning the answer should be

```julia
A.*B = [1 1 1; 2 2 2; 3 3 3]

```

Now I want to covert this matrix to a row vector like this

```julia
Z = [1;1;1;2;2;2;3;3;3]

```

How can i do that? any suggestions? thank you

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [November 17, 2022, 9:18pm UTC](https://discourse.julialang.org/t/matrix-to-row-vector/90417/2 "2022-11-17T21:18:29Z")

</div>

`vec((A .* B)')`

(Note that Julia arrays are stored by column, so if you are coming from Python where arrays are stored by row you might consider [transposing your array layouts for efficiency](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-column-major).)

---

<div class="post-metadata">

### Author: ![Muhammad\_Nadeem](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@Muhammad\_Nadeem](https://discourse.julialang.org/u/Muhammad_Nadeem)
#### Post date: [November 17, 2022, 9:22pm UTC](https://discourse.julialang.org/t/matrix-to-row-vector/90417/3 "2022-11-17T21:22:31Z")

</div>

Thank you 🙂
