def test_identity(self): m1 = Matrix.identity(1) self.assertEqual(m1.rows(), 1) self.assertEqual(m1.columns(), 1) self.assertEqual(m1[0,0], 1) with self.assertRaises(ValueError): Matrix.identity(0) with self.assertRaises(ValueError): Matrix.identity(-3) m = Matrix.identity(17) self.assertEqual(m.rows(), 17) self.assertEqual(m.columns(), 17) for i in range(17): for j in range(17): elt = m[i, j] if i == j: self.assertEqual(elt, 1) else: self.assertEqual(elt, 0)
def _n_identity_mcs(self, n=6, s=3): """return n copies of the identity matrix on s*s elts""" return tuple([Matrix.identity(s) for i in range(n)])