# How to specify a matrix, or a column, or a row of that matrix

**URL:** <https://discourse.julialang.org/t/how-to-specify-a-matrix-or-a-column-or-a-row-of-that-matrix/20314>\
**Category:** New to Julia\
**Created:** [January 31, 2019, 2:08pm UTC](https://discourse.julialang.org/t/how-to-specify-a-matrix-or-a-column-or-a-row-of-that-matrix/20314 "2019-01-31T14:08:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [January 31, 2019, 2:08pm UTC](https://discourse.julialang.org/t/how-to-specify-a-matrix-or-a-column-or-a-row-of-that-matrix/20314/1 "2019-01-31T14:08:18Z")

</div>

I feel really basic, but I cannot figure out how to do it.

For certain formulas I need to multiply each element of a matrix (I know this can be done by using `.`) But I also need to be able to specify whether to use only columns or rows of a matrix.

So sometimes I need `a[i,j]`, sometimes I need `a[i,]` and sometimes `a[,j]`. I thought I could use `'` but this flips the matrix diagonally (Its `The conjugate transposition operator`) and I am not confident that this is what I need to use.

In R the code is

```julia
F.function = function(i,j,a, B, q, Th){
  num = a[i,j] * B[j]^q
  den = 1 + sum(Th[,j]*a[,j]*B^q)
  return(num/den)
}

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [January 31, 2019, 2:09pm UTC](https://discourse.julialang.org/t/how-to-specify-a-matrix-or-a-column-or-a-row-of-that-matrix/20314/2 "2019-01-31T14:09:26Z")

</div>

Do you mean `a[i, :]` and `a[:, j]`?

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [January 31, 2019, 2:12pm UTC](https://discourse.julialang.org/t/how-to-specify-a-matrix-or-a-column-or-a-row-of-that-matrix/20314/3 "2019-01-31T14:12:15Z")

</div>

it may also help to notice that `a[i,:]` is a flat vector, while `a[i:i,:]` is a 1xn array

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [January 31, 2019, 2:13pm UTC](https://discourse.julialang.org/t/how-to-specify-a-matrix-or-a-column-or-a-row-of-that-matrix/20314/4 "2019-01-31T14:13:30Z")

</div>

Ah… you see, I thought there must be a very obvious answer that I was over looking. Thank you!

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [January 31, 2019, 2:18pm UTC](https://discourse.julialang.org/t/how-to-specify-a-matrix-or-a-column-or-a-row-of-that-matrix/20314/5 "2019-01-31T14:18:06Z")

</div>

I do not see how one is a flat vector and the other an array. I understand `a[i:i,:]` as being from the first to last instance of `i` (which would be useful if one wanted to specify certain rows/columns)? Where as I understand `a[i,:]` as specifying the whole row. Is this incorrect?

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [January 31, 2019, 2:29pm UTC](https://discourse.julialang.org/t/how-to-specify-a-matrix-or-a-column-or-a-row-of-that-matrix/20314/6 "2019-01-31T14:29:44Z")

</div>

`a[i,:]`and `a[i:i,:]` contain the same elements, they just have different “forms”: the first is a vector, the other a 1xn matrix. This distinction is sometimes useful. If not, go for the vector version.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [January 31, 2019, 5:53pm UTC](https://discourse.julialang.org/t/how-to-specify-a-matrix-or-a-column-or-a-row-of-that-matrix/20314/7 "2019-01-31T17:53:40Z")

</div>

The relevant part of the manual contains further info  
[https://docs.julialang.org/en/v1/manual/arrays/#man-array-indexing-1](https://docs.julialang.org/en/v1/manual/arrays/#man-array-indexing-1)
