Operators
@= — Matrix multiplication assignment
Apply a type-defined matrix multiplication and store its result. Python built-in numbers and lists do not provide matrix multiplication. A class can implement a shape-aware operation; no numerical package is required for the local example. The __imatmul__() hook may modify its receiver or supply a replacement. If absent or declining with NotImplemented, normal binary dispatch applies. The result is stored back into the target; this is a statement, not an expression. A failed store does not guarantee rollback.
Formal Syntax & Structure
python syntaxpython
target @= expressionParameters & Attributes
| Name | Type | Description |
|---|---|---|
| target | object | Existing assignable name, attribute, item or slice; its current value participates in the operation. |
| right | compatible matrix operand or custom object | Value used as the right operand of the operation. |
Working Example
Example Snippetpython
class Row: def __init__(self, values): self.values = values def __matmul__(self, column): if len(self.values) != len(column): raise ValueError("length mismatch") return sum(a * b for a, b in zip(self.values, column))
row = Row([2, 3])row @= [4, 5]print(row)