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


#1

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

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)
}

#2

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


#3

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


#4

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


#5

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?


#6

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.


#7

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