Operator Functions

operator.imatmul()

Apply in-place matrix multiplication, falling back to ordinary matrix multiplication if appropriate. Return the resulting object; the caller must retain it.

Formal Syntax & Structure

python syntaxpython
operator.imatmul(a, b, /)

Parameters & Attributes

NameTypeDescription
aobjectLeft operand or target object.
bobjectRight 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 selfa=Matrix(3)result=operator.imatmul(a,Matrix(4))print(result is a, a.value)
Python Reference