0
$\begingroup$

In the Mahalanobis distance there are both $(\vec{x}-\vec{y})^T$ and $(\vec{x}-\vec{y})$. Which one is a column vector and which one is row vector? I need to write this in R, so vector orientation is important.

$\endgroup$
0
$\begingroup$

$(\vec{x}-\vec{y})^T$ is the row vector. Only then the matrix multiplication is feasible.

$\endgroup$
0
$\begingroup$

With S as your covariance matrix, the R code would be the following:

d <- sqrt(t(x-y) %*% solve(S) %*% (x-y))

Vectors are typically assumed to be column vectors.

$\endgroup$
3
  • $\begingroup$ My vectors are rows cut from matrix like mat[i,]. Therefore I should have sqrt((x-y) %*% solve(S) %*% t(x-y))? $\endgroup$
    – qalis
    Jun 21 '19 at 19:28
  • $\begingroup$ I tried it in R, and it seems to be converting mat[i,] to a column vector, meaning that your code does not work. I was expecting yours to work, since mat[i,] is a row vector, but R seems to change them to column vectors. $\endgroup$
    – Dave
    Jun 21 '19 at 19:40
  • $\begingroup$ That's interesting, thank you. $\endgroup$
    – qalis
    Jun 22 '19 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.