0

So I tried to study about TOPSIS. Here is the reference. In the first normalizing step, there is code like this:

divisors[j] = np.sqrt(column @ column)

I tried to look the meaning of @, but I still couldn't find it. Based on the formula, at the divisor, we need to square the xij first, then sum, then do the square root. At code, when do the column values be summed together?

Ch3steR
  • 20,090
  • 4
  • 28
  • 58
user119420
  • 107
  • 10
  • 1
    Dupe: https://stackoverflow.com/q/6392739, `@` is used for matrix multiplication here. – Ch3steR May 11 '22 at 03:34
  • @Ch3steR if it's matrix multiplication, matrix column is matrix with size 1x5, so it should be multiplied by matrix with size 5x1 – user119420 May 11 '22 at 03:43
  • For numpy arrays, it's the operator form of `np.matmul`. For 2d arrays this is the same as `np.dot` – hpaulj May 11 '22 at 03:47
  • judging from its name, `column` is a vector right? in that case, `@` is the same as the inner product of two vectors. –  May 11 '22 at 03:48

1 Answers1

0

If I understand your question correctly, you are trying to compute:

np.sqrt(np.dot(column, column))

This will first square each element of column, then sum the squared elements, then take the square root of the sum. It will work if column is an array with shape (n,) or (n,1) or (1,n).

As has already been pointed out in the comments, @ is for matrix multiplication. So if column has shape (n, 1), then np.sqrt(column.T @ column) will achieve the same result.

LarryBird
  • 333
  • 1
  • 7