本文整理汇总了Python中matrix.Matrix.setRow方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.setRow方法的具体用法?Python Matrix.setRow怎么用?Python Matrix.setRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.setRow方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_adding_rows
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import setRow [as 别名]
def test_adding_rows(self):
columns = 2
rows = 3
matrix = Matrix(rows, columns)
self.assertRaises(ValueError, matrix.setRow, 1, [1, 2, 3])
matrix.setRow(2, [2, 5])
self.assertEqual(matrix.getRow(1), [0, 0])
self.assertEqual(matrix.getRow(2), [2, 5])
示例2: testLowerDecomposition
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import setRow [as 别名]
def testLowerDecomposition(self):
columns = 3
rows = 3
matrix = Matrix(rows, columns)
matrix.setRow(1, [1, 2, 3])
matrix.setRow(2, [4, 5, 6])
matrix.setRow(3, [7, 8, 9])
lu_matrix_list = matrix.get_lu_decomposition()
new_matrix = lu_matrix_list[0] * lu_matrix_list[1]
self.assertEqual(matrix.matrix, new_matrix.matrix)
示例3: test_multiplying_matrixes
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import setRow [as 别名]
def test_multiplying_matrixes(self):
matrix1 = Matrix(2, 3)
matrix1.setRow(1, [3, 2, 1])
matrix1.setRow(2, [1, 0, 2])
matrix2 = Matrix(3, 2)
matrix2.setColumn(1, [1, 0, 4])
matrix2.setColumn(2, [2, 1, 0])
matrixWithWrongDimension = Matrix(5, 6)
with self.assertRaises(TypeError):
matrix2 * matrixWithWrongDimension
correctMultipliedMatrix = Matrix(2, 2)
correctMultipliedMatrix.setRow(1, [7, 8])
correctMultipliedMatrix.setRow(2, [9, 2])
multipliedMatrix = matrix1 * matrix2
self.assertEqual(multipliedMatrix.matrix,
correctMultipliedMatrix.matrix)
示例4: test_multiplying_matrixes_with_floats
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import setRow [as 别名]
def test_multiplying_matrixes_with_floats(self):
matrix1 = Matrix(2, 3)
matrix1.setRow(1, [3.5, 2, 1])
matrix1.setRow(2, [1, 0, 2.5])
matrix2 = Matrix(3, 2)
matrix2.setColumn(1, [0.5, 0, 4])
matrix2.setColumn(2, [2, 1.375, 0])
correctMultipliedMatrix = Matrix(2, 2)
correctMultipliedMatrix.setRow(1, [5.75, 9.75])
correctMultipliedMatrix.setRow(2, [10.5, 2])
multipliedMatrix = matrix1 * matrix2
self.assertEqual(multipliedMatrix.matrix,
correctMultipliedMatrix.matrix)