From the documentation:

The @ (at) operator is intended to be used for matrix multiplication. No builtin Python types implement this operator.

The @ operator was introduced in Python 3.5. @= is matrix multiplication followed by assignment, as you would expect. They map to __matmul__, __rmatmul__ or __imatmul__ similar to how + and += map to __add__, __radd__ or __iadd__.

The operator and the rationale behind it are discussed in detail in PEP 465.

Answer from user1804599 on Stack Overflow
Top answer
1 of 4
276

From the documentation:

The @ (at) operator is intended to be used for matrix multiplication. No builtin Python types implement this operator.

The @ operator was introduced in Python 3.5. @= is matrix multiplication followed by assignment, as you would expect. They map to __matmul__, __rmatmul__ or __imatmul__ similar to how + and += map to __add__, __radd__ or __iadd__.

The operator and the rationale behind it are discussed in detail in PEP 465.

2 of 4
131

@= and @ are new operators introduced in Python 3.5 performing matrix multiplication. They are meant to clarify the confusion which existed so far with the operator * which was used either for element-wise multiplication or matrix multiplication depending on the convention employed in that particular library/code. As a result, in the future, the operator * is meant to be used for element-wise multiplication only.

As explained in PEP0465, two operators were introduced:

  • A new binary operator A @ B, used similarly as A * B
  • An in-place version A @= B, used similarly as A *= B

Matrix Multiplication vs Element-wise Multiplication

To quickly highlight the difference, for two matrices:

A = [[1, 2],    B = [[11, 12],
     [3, 4]]         [13, 14]]
  • Element-wise multiplication will yield:

    A * B = [[1 * 11,   2 * 12], 
             [3 * 13,   4 * 14]]
    
  • Matrix multiplication will yield:

    A @ B  =  [[1 * 11 + 2 * 13,   1 * 12 + 2 * 14],
               [3 * 11 + 4 * 13,   3 * 12 + 4 * 14]]
    

Usage in Numpy

So far, Numpy used the following convention:

  • the * operator (and arithmetic operators in general) were defined as element-wise operations on ndarrays and as matrix-multiplication on numpy.matrix type.

  • method/function dot was used for matrix multiplication of ndarrays

Introduction of the @ operator makes the code involving matrix multiplications much easier to read. PEP0465 gives us an example:

# Current implementation of matrix multiplications using dot function
S = np.dot((np.dot(H, beta) - r).T,
            np.dot(inv(np.dot(np.dot(H, V), H.T)), np.dot(H, beta) - r))

# Current implementation of matrix multiplications using dot method
S = (H.dot(beta) - r).T.dot(inv(H.dot(V).dot(H.T))).dot(H.dot(beta) - r)

# Using the @ operator instead
S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r)

Clearly, the last implementation is much easier to read and interpret as an equation.

Discussions

Calling matrix multiplication from python - Python - OpenCV
I’m wondering if there is a way to access the matrix multiply operators from python. Specifically, the C++ documentation mentions the ability to use matrix multplication that is different than mul. https://docs.opencv.… More on forum.opencv.org
🌐 forum.opencv.org
0
August 2, 2022
python - What does the @-operator do? - Blender Stack Exchange
I've been trying to figure out what the @ in the following code does: T_world2bcam = -1*R_world2bcam @ cam.location where R_world2bcam is a 3x3 Matrix and cam.location is a Vector. The code is fro... More on blender.stackexchange.com
🌐 blender.stackexchange.com
February 28, 2022
python - Differences between the "@" operator and np.matmul() - Stack Overflow
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? More on stackoverflow.com
🌐 stackoverflow.com
python3.5 support and @ operator with __matmul__ method
Are there any plans to include Python3.5 support (incl. binaries) and dedicated matmul @ operator? More on github.com
🌐 github.com
14
September 16, 2015
🌐
Python
peps.python.org › pep-0465
PEP 465 – A dedicated infix operator for matrix multiplication | peps.python.org
A new AST node is added named MatMult, along with a new token ATEQUAL and new bytecode opcodes BINARY_MATRIX_MULTIPLY and INPLACE_MATRIX_MULTIPLY. Two new type slots are added; whether this is to PyNumberMethods or a new PyMatrixMethods struct remains to be determined. Why @ instead of some other spelling? There isn’t any consensus across other programming languages about how this operator ...
🌐
Alysivji
alysivji.com › python-matrix-multiplication-operator.html
@ Python's Matrix Multiplication Operator - Siv Scripts
The Python Data Model specifies that the @ operator invokes __matmul__ and __rmatmul__.
🌐
DataCamp
datacamp.com › doc › numpy › matrix-multiplication
NumPy Matrix Multiplication
Matrix multiplication in NumPy is used when you need to perform dot product operations between two matrices or a matrix and a vector. The numpy.matmul() or the @ operator can be used for this purpose.
Find elsewhere
🌐
OpenCV
forum.opencv.org › python
Calling matrix multiplication from python - Python - OpenCV
August 2, 2022 - I’m wondering if there is a way to access the matrix multiply operators from python. Specifically, the C++ documentation mentions the ability to use matrix multplication that is different than mul. https://docs.opencv.…
🌐
YouTube
youtube.com › koolac
Matrix Multiplication in Python using NumPy (using @ operator, matmul and dot) - YouTube
How to do Matrix Multiplication in Python NumPy (using @ operator, matmul and dot). In this Video we talk about 3 different ways in order to do Matrix Multip...
Published   December 9, 2022
Views   1K
🌐
Python
docs.python.org › 3 › library › operator.html
operator — Standard operators as functions
operator.matmul(a, b)¶ · operator.__matmul__(a, b)¶ · Return a @ b. Added in version 3.5. operator.neg(obj)¶ · operator.__neg__(obj)¶ · Return obj negated (-obj). operator.or_(a, b)¶ · operator.__or__(a, b)¶ · Return the bitwise or of a and b. operator.pos(obj)¶ ·
🌐
Medium
medium.com › analytics-vidhya › python-matrix-multiplication-using-a-dedicated-infix-operator-b0a41b68904f
Python Matrix Multiplication using a Dedicated Infix Operator @
March 15, 2024 - The * operator in Python was used for element wise multiplication and matrix multiplication. There was various proposals for making this two operations separate and none of then worked.
🌐
TutorialsPoint
tutorialspoint.com › home › numpy › numpy matmul function
NumPy Matmul Function
March 5, 2015 - The numpy.matmul() function returns the matrix product of two arrays.
🌐
Finxter
blog.finxter.com › home › learn python blog › numpy matrix multiplication — np.matmul() and @ [ultimate guide]
NumPy Matrix Multiplication - np.matmul() and @ [Ultimate Guide] - Be on the Right Side of Change
November 11, 2023 - NumPy’s np.matmul() and the @ operator perform matrix multiplication. They compute the dot product of two arrays. For 2D arrays, it’s equivalent to matrix multiplication, while for higher dimensions, it’s a sum product over the last axis ...
🌐
Codingem
codingem.com › home › numpy @ operator—matrix multiplication in python
NumPy @ Operator—Matrix Multiplication in Python - codingem.com
July 10, 2025 - As of Python 3.5, it has been possible to specify a matrix multiplication operator @ to a custom class. This happens by overriding the special method called __matmul__.
🌐
ProgramCreek
programcreek.com › python › example › 94648 › operator.matmul
Python Examples of operator.matmul
def test_matmul(self): if not TEST_MATMUL: pytest.skip("matmul is only tested in Python 3.5+") D = {'shape': self.A.shape, 'matvec': lambda x: np.dot(self.A, x).reshape(self.A.shape[0]), 'rmatvec': lambda x: np.dot(self.A.T.conj(), x).reshape(self.A.shape[1]), 'matmat': lambda x: np.dot(self.A, x)} A = interface.LinearOperator(**D) B = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) b = B[0] assert_equal(operator.matmul(A, b), A * b) assert_equal(operator.matmul(A, B), A * B) assert_raises(ValueError, operator.matmul, A, 2) assert_raises(ValueError, operator.matmul, 2, A)
🌐
GitHub
github.com › tensorflow › tensorflow › issues › 1062
python3.5 support and @ operator with __matmul__ method · Issue #1062 · tensorflow/tensorflow
September 16, 2015 - Are there any plans to include Python3.5 support (incl. binaries) and dedicated matmul @ operator?
Published   Feb 11, 2016
🌐
Delft Stack
delftstack.com › home › howto › numpy › numpy dot vs matmul
NumPy dot vs matmul in Python | Delft Stack
November 26, 2021 - We have functions available to carry out multiplication between them in Python. The two methods used are the numpy.dot() function and the @ operator (the array’s __matmul__ method).