Python 3.5+operatorfunction
operator.matmul
matrix multiplication
Matrix multiplication: a @ b (invokes __matmul__).
Syntax
operator.matmul(a, b)
No built-in type supports @: matmul(2, 3) raises TypeError. The operator arrived in Python 3.5 (PEP 465) specifically for linear-algebra libraries such as NumPy and PyTorch. Your own class gains support through __matmul__ and the reflected __rmatmul__.
Examples
import operator
class M:
def __matmul__(self, other): return 'mm'
print(operator.matmul(M(), M())) # → mm
See also
Open in the full glossarydocs.python.orgReport an inaccuracy