Sponsored Reserved space — layout preview until AdSense is connected
medium +22 pts

Matrix addition operator

Dunder methods for numeric types.

Implement `class Matrix` with: - `__init__(data: list[list[float]])` — store grid - `__add__(other) -> Matrix` — element-wise addition - `__mul__(other) -> Matrix` — matrix multiplication (dot product) - `__repr__` — human-readable

Constraints

All matrices have matching dimensions for the operations used.

Example

A = Matrix([[1,2],[3,4]])
B = Matrix([[5,6],[7,8]])
(A + B).data  # [[6,8],[10,12]]
22 points ~20 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

__add__: zip rows and element-wise add. __mul__: classic triple loop or use row × column dot product.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.
Sponsored Reserved space — layout preview until AdSense is connected