2

Is there an advantage to using the @ operator over numpy.matmul when multiplying vectors, matrices, etc? Is this mainly for readability? Whats is the convention?

Ehsan
  • 11,523
  • 2
  • 17
  • 30
Gonzo
  • 85
  • 4
  • 2
    Does this answer your question? [Difference between numpy dot() and Python 3.5+ matrix multiplication @](https://stackoverflow.com/questions/34142485/difference-between-numpy-dot-and-python-3-5-matrix-multiplication) – Warcupine Jul 31 '20 at 19:44
  • Basically the same as the choice between `np.add` and `+`, or `np.multiply` and `*`. – hpaulj Jul 31 '20 at 19:50
  • 1
    `@` was added precisely because [the Numpy community wanted an infix operator to replace explicit use of `matmul`](https://www.python.org/dev/peps/pep-0465/#motivation). – chepner Jul 31 '20 at 20:25

1 Answers1

3

As the doc explains: The matmul function implements the semantics of the @ operator introduced in Python 3.5 following PEP465.

So basically, @ is the same as np.matmul without method parameters.

Ehsan
  • 11,523
  • 2
  • 17
  • 30