本文整理汇总了Python中Matrix.Matrix.set_row方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.set_row方法的具体用法?Python Matrix.set_row怎么用?Python Matrix.set_row使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.set_row方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_setrowcol
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import set_row [as 别名]
def test_setrowcol(self):
A = Matrix([1, 2, 3, 4],
[5, 6, 7, 8])
A.set_row(0, [4, 3, 2, 1])
self.assertEqual(A, Matrix([4, 3, 2, 1],
[5, 6, 7, 8]))
A.set_col(2, [9, 8])
self.assertEqual(A, Matrix([4, 3, 9, 1],
[5, 6, 8, 8]))
示例2: test_det
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import set_row [as 别名]
def test_det(self):
# Test property that determinant of identity matrix is 1
A = Matrix(10, 10, mtype="i")
self.assertAlmostEqual(lalg.det(A), 1, delta=0.001)
# Test property row exchanges case that determinant is (-1)^swaps
A.swap(1, 2)
self.assertAlmostEqual(lalg.det(A), -1, delta=0.001)
A.swap(3, 4)
self.assertAlmostEqual(lalg.det(A), 1, delta=0.001)
# Multiplying one row of a matrix by t results in the determinant being multiplied by t
# | t*a t*b | = t * |a b|
# | c d | |c d|
A = Matrix([4 * 2, 4 * 8], [3, 9])
B = Matrix([2, 8], [3, 9])
self.assertAlmostEqual(lalg.det(A), 4 * lalg.det(B), delta=0.001)
# Adding to one row of a matrix results in a linear combination of the matrix and addition
# | a+da b+db | = |a b| + |da db|
# | c d | |c d| |c d |
A = Matrix([8 + 9, -2 + 7], [-5, 12])
B = Matrix([8, -2], [-5, 12])
C = Matrix([9, 7], [-5, 12])
self.assertAlmostEqual(lalg.det(A), lalg.det(B) + lalg.det(C), delta=0.001)
# If A has a row of all zeros the determinant should be 0
A = Matrix(12, 12)
for i in range(12):
for j in range(12):
A[i][j] = random.randint(-1000, 1000)
A.set_row(3, [0] * 12)
self.assertAlmostEqual(lalg.det(A), 0)
# If two rows are equal the determinant is 0
A = Matrix(12, 12)
for i in range(12):
for j in range(12):
A[i][j] = random.randint(-1000, 1000)
A.set_row(random.randint(0, 5), [i for i in range(12)])
A.set_row(random.randint(6, 11), [i for i in range(12)])
self.assertAlmostEqual(lalg.det(A), 0)