Operator Functions
operator.matmul()
Apply the matrix multiplication protocol (a @ b). Built-in numbers do not provide matrix multiplication; the operand class defines its meaning.
Formal Syntax & Structure
python syntaxpython
operator.matmul(a, b, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| a | object | Left operand or target object. |
| b | object | Right operand. |
Return Value
object
The object result described above.
Working Example
Example Snippetpython
import operatorclass Matrix: def __init__(self, value): self.value=value def __matmul__(self, other): return Matrix(self.value*other.value) def __imatmul__(self, other): self.value *= other.value; return selfprint(operator.matmul(Matrix(3), Matrix(4)).value)