-2

I am reading someone's code, where the operator "@" appears (in fact, I am not even sure whether @ is an operator or not).

I searched around, but could not get any clues. I guess it's some advanced usage.

Here is some example code:

hidden = self.adj_norm @ tf.sparse_tensor_dense_matmul(hidden, w) + b

hidden = self.adj_norm @ hidden @ w + b

final_output = self.adj_norm @ tf.sparse_tensor_dense_matmul(final_output, w) + b

final_output = self.adj_norm @ final_output @ w + b

Can somebody explain or provide some references that I can check for the usage of "@"?

tomerpacific
  • 3,871
  • 11
  • 28
  • 48
Paradox
  • 137
  • 5
  • What does `+` mean. It depends on what it's applied to. In your case looks like `@` is used as dot product. – Julien Apr 23 '19 at 05:44

1 Answers1

5

Mostly @ is used as a decorator. In your case however, it seems it is used for matrix multiplication.

In python matrix multiplication, x @ y invokes x.__matmul__(y) or:

x @ y
#equivalent to

dot(x, y)
and

x @= y
#equivalent to

x = dot(x, y)

Dot is the matrix multiplication function in Numpy and x and y.

Matthias
  • 11,699
  • 5
  • 39
  • 45
Yash
  • 3,208
  • 2
  • 14
  • 30