本文整理汇总了Python中matrix.Matrix.setColumn方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.setColumn方法的具体用法?Python Matrix.setColumn怎么用?Python Matrix.setColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.setColumn方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multiplying_big_matrixes
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import setColumn [as 别名]
def test_multiplying_big_matrixes(self):
#this only tests speed and not correctness
matrix1 = Matrix(20, 20)
matrix2 = Matrix(20, 20)
for i in range(1, matrix1.rowCount + 1):
matrix2.setColumn(i, [random.randint(0, 5000) for i in range(20)])
matrix1.setColumn(i, [random.randint(0, 5000) for i in range(20)])
matrix1 * matrix2
示例2: test_adding_columns
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import setColumn [as 别名]
def test_adding_columns(self):
columns = 2
rows = 3
matrix = Matrix(rows, columns)
self.assertRaises(ValueError, matrix.setColumn, 1, [1, 2, 3, 4])
matrix.setColumn(1, [1, 2, 3])
matrix.setColumn(2, [4, 5, 6])
self.assertEqual(matrix.matrix, [[1, 4], [2, 5], [3, 6]])
self.assertEqual(matrix.getColumn(1), [1, 2, 3])
示例3: test_multiplying_matrixes_with_floats
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import setColumn [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)
示例4: test_multiplying_matrixes
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import setColumn [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)