A Pure-Python Matrix Class

medium
Unit 12 · Classes0/2 to milestone

Implement Matrix(rows) (a list of equal-length lists; raise ValueError otherwise) with:

  • shape property, T property (transpose), __eq__
  • + and - with another matrix of the same shape (else ValueError)
  • @ matrix multiplication (inner dimensions must match)
  • * by a number (both sides)
  • Matrix.identity(n) class method
  • __pow__(k) for a non-negative integer k on square matrices, using repeated squaring
#classes#linear-algebra2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
A Pure-Python Matrix Class · TechGradify