@= Matrix multiplication assignment
Last updated: 2026-09-22
@= Matrix multiplication assignment
@= performs an in-place matrix multiplication of the left variable by the right, equivalent to x = x @ y.
| Category | Operators |
|---|---|
| Kind | Operator |
📝 Syntax
x @= y
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
[[19, 22], [43, 50]]
ℹ️ Info @= requires a library such as numpy for matrix multiplication; plain built-in types do not define this operation.
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat environment does @= require?
AThe object must implement `__imatmul__` or `__matmul__`, typically with NumPy: `a @= b` does an in-place matrix multiplication on arrays. Built-in `list` and `int` do not support it and raise `TypeError`.
QIs there a difference between @= and a = a @ b?
A`@=` first tries `__imatmul__` for an in-place operation (NumPy arrays are modified in place); if there is no `__imatmul__`, it falls back to `a = a @ b`. The results are usually the same, but the object's `id` may differ.
QCan I use @= without installing NumPy?
AYes. A custom class that implements `__imatmul__` (or `__matmul__`) supports `@=`; built-in `list` and `int` have no such implementation, so they raise `TypeError`.