当前位置: 首页>>代码示例>>Python>>正文


Python Matrix.set方法代码示例

本文整理汇总了Python中matrix.Matrix.set方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.set方法的具体用法?Python Matrix.set怎么用?Python Matrix.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matrix.Matrix的用法示例。


在下文中一共展示了Matrix.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_negate

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
    def test_negate(self):
        self.assertEqual(-self.m, self.m)

        m = Matrix(3, 3)
        m.set(0, 0, -1)
        m.set(1, 1, -1)
        m.set(2, 2, -1)

        self.assertEqual(-self.e, m)
开发者ID:liquidmetal,项目名称:linear-algebra,代码行数:11,代码来源:matrix_test.py

示例2: testMatrixSet

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
    def testMatrixSet(self):
        """Изменение значений матрицы"""

        # тестируем механизм изменения значений элементов матрицы
        m = Matrix(1, 2)

        m.set(0, 0, 1)
        m.set(0, 1, 2)

        self.assertEqual(m.get(0, 0), 1)
        self.assertEqual(m.get(0, 1), 2)
开发者ID:EfimRyabushev,项目名称:lab12,代码行数:13,代码来源:Tests.py

示例3: test_transpose

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
    def test_transpose(self):
        self.m.set(1, 0, 10)
        self.m.transpose()
        
        against = Matrix(3, 3)
        against.set(0, 1, 10)

        self.assertEqual(self.m, against)

        against = Matrix.eye(3)
        self.e.transpose()
        self.assertEqual(self.e, against)
开发者ID:liquidmetal,项目名称:linear-algebra,代码行数:14,代码来源:matrix_test.py

示例4: testMatrixCompare

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
    def testMatrixCompare(self):
        """Сравнение матриц"""

        # создаём две одинаковые матрицы и сравниваем их между собой
        m1 = Matrix(1, 2)
        m2 = Matrix(1, 2)

        self.assertEqual(m1, m2)

        # меняем значение одного элемента второй матрицы и снова сравниваем
        # матрицы между собой
        m2.set(0, 0, 1)

        self.assertNotEqual(m1, m2)
开发者ID:EfimRyabushev,项目名称:lab12,代码行数:16,代码来源:Tests.py

示例5: test_determinant

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
    def test_determinant(self):
        self.assertEqual(self.e.det(), 1)
        self.assertEqual(self.m.det(), 0)

        m = Matrix(3, 3)
        m.set(0, 0, 1)
        m.set(0, 1, 2)
        m.set(0, 2, 3)
        m.set(1, 0, 4)
        m.set(1, 1, 5)
        m.set(1, 2, 6)
        m.set(2, 0, 7)
        m.set(2, 1, 8)
        m.set(2, 2, 9)
        self.assertEqual(m.det(), 0)
开发者ID:liquidmetal,项目名称:linear-algebra,代码行数:17,代码来源:matrix_test.py

示例6: calculate_QR

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
def calculate_QR(mat):
	q_list = []
	R = Matrix(mat.size())

	for i in range(mat.size()):
		vector = Vector(mat.get_col(i))

		aux_vec = Vector([0] * mat.size())
		for j in range(i):
			prod = vector.dot_product(q_list[j])
			R.set(j,i, prod)
			aux_vec += q_list[j] * prod

		e = vector - aux_vec
		R.set(i,i,e.get_norm())
		q_list.append(e.normalize())

	return Matrix.from_col_lists([x.get_values() for x in q_list]), R
开发者ID:federicotdn,项目名称:mna-tp1,代码行数:20,代码来源:problem3.py

示例7: testMatrixScalarDiv

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
    def testMatrixScalarDiv(self):
        """Деление матрицы на число"""

        # делим матрицу на число и проверяем результат
        a = Matrix(3, 2)
        a.set(0, 0, 1)
        a.set(0, 1, 2)
        a.set(1, 0, 3)
        a.set(1, 1, 4)
        a.set(2, 0, 5)
        a.set(2, 1, 6)

        b = a * 2

        self.assertEqual(b / 2, a)

        b = a * 3

        self.assertEqual(b / 1.5, a + a)
开发者ID:EfimRyabushev,项目名称:lab12,代码行数:21,代码来源:Tests.py

示例8: testMatrixScalarMul

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
    def testMatrixScalarMul(self):
        """Умножение матрицы на число"""

        # умножаем матрицу на число и проверяем результат
        _a = Matrix(3, 2)
        _a.set(0, 0, 1)
        _a.set(0, 1, 2)
        _a.set(1, 0, 3)
        _a.set(1, 1, 4)
        _a.set(2, 0, 5)
        _a.set(2, 1, 6)

        a = _a * 2

        b = a * 2

        self.assertEqual(b, a + a)

        b = a * 1.5

        self.assertEqual(b, _a + _a + _a)
开发者ID:EfimRyabushev,项目名称:lab12,代码行数:23,代码来源:Tests.py

示例9: testMatrixAdd

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
    def testMatrixAdd(self):
        """Сложение матриц"""

        # складываем две матрицы и проверяем результат
        a = Matrix(3, 2)

        a.set(0, 0, -1)
        a.set(0, 1, -2)
        a.set(1, 0, -3)
        a.set(1, 1, -4)
        a.set(2, 0, -5)
        a.set(2, 1, -6)

        b = Matrix(3, 2)

        b.set(0, 0, 1)
        b.set(0, 1, 2)
        b.set(1, 0, 3)
        b.set(1, 1, 4)
        b.set(2, 0, 5)
        b.set(2, 1, 6)

        _c = Matrix(3, 2)

        c = a + b

        self.assertEqual(c, _c)
开发者ID:EfimRyabushev,项目名称:lab12,代码行数:29,代码来源:Tests.py

示例10: testMatrixMul

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
    def testMatrixMul(self):
        """Матричное умножение"""

        # выполняем матричное умножение и проверяем результат
        a = Matrix(2, 3)
        a.set(0, 0, 1)
        a.set(0, 1, 2)
        a.set(0, 2, 3)
        a.set(1, 0, 4)
        a.set(1, 1, 5)
        a.set(1, 2, 6)

        b = Matrix(3, 2)
        b.set(0, 0, 9)
        b.set(0, 1, 8)
        b.set(1, 0, 7)
        b.set(1, 1, 6)
        b.set(2, 0, 5)
        b.set(2, 1, 4)

        c = Matrix(2, 2)
        c.set(0, 0, 38)
        c.set(0, 1, 32)
        c.set(1, 0, 101)
        c.set(1, 1, 86)

        self.assertEqual(a * b, c)
开发者ID:EfimRyabushev,项目名称:lab12,代码行数:29,代码来源:Tests.py

示例11: testTranspose

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
    def testTranspose(self):
        """Траспонирование матрицы"""

        # выполняем транспонирование матрицы и проверяем результат
        a = Matrix(3, 2)
        a.set(0, 0, 1)
        a.set(0, 1, 2)
        a.set(1, 0, 3)
        a.set(1, 1, 4)
        a.set(2, 0, 5)
        a.set(2, 1, 6)

        b = Matrix(2, 3)
        b.set(0, 0, 1)
        b.set(1, 0, 2)
        b.set(0, 1, 3)
        b.set(1, 1, 4)
        b.set(0, 2, 5)
        b.set(1, 2, 6)

        self.assertEqual(a.transpose(), b)
开发者ID:EfimRyabushev,项目名称:lab12,代码行数:23,代码来源:Tests.py

示例12: testMatrixSub

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
    def testMatrixSub(self):
        """Вычитание матриц"""

        # вычитаем две матрицы и проверяем результат
        a = Matrix(3, 2)

        a.set(0, 0, 1)
        a.set(0, 1, 2)
        a.set(1, 0, 3)
        a.set(1, 1, 4)
        a.set(2, 0, 5)
        a.set(2, 1, 6)

        b = Matrix(3, 2)

        b.set(0, 0, 1)
        b.set(0, 1, 2)
        b.set(1, 0, 3)
        b.set(1, 1, 4)
        b.set(2, 0, 5)
        b.set(2, 1, 6)

        _c = Matrix(3, 2)

        c = a - b

        self.assertTrue(c, _c)
开发者ID:EfimRyabushev,项目名称:lab12,代码行数:29,代码来源:Tests.py

示例13: TestMatrix

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
class TestMatrix(unittest.TestCase):
    def setUp(self):
        self.m = Matrix(3, 3)
        self.e = Matrix.eye(3)
        pass

    def tearDown(self):
        pass

    def test_create(self):
        self.assertNotEqual(self.m, None)

    def test_transpose(self):
        self.m.set(1, 0, 10)
        self.m.transpose()
        
        against = Matrix(3, 3)
        against.set(0, 1, 10)

        self.assertEqual(self.m, against)

        against = Matrix.eye(3)
        self.e.transpose()
        self.assertEqual(self.e, against)

    def test_add(self):
        self.assertEqual(self.m + self.e, self.e)


    def test_subtract(self):
        self.assertEqual(self.e - self.m, self.e)

    def test_negate(self):
        self.assertEqual(-self.m, self.m)

        m = Matrix(3, 3)
        m.set(0, 0, -1)
        m.set(1, 1, -1)
        m.set(2, 2, -1)

        self.assertEqual(-self.e, m)

    def test_pos(self):
        self.assertEqual(+self.m, self.m)
        self.assertEqual(+self.e, self.e)

    def test_submatrix(self):
        e2 = Matrix.eye(2)
        self.assertEqual(e2, self.e.submatrix(range(2), range(2)))

    def test_determinant(self):
        self.assertEqual(self.e.det(), 1)
        self.assertEqual(self.m.det(), 0)

        m = Matrix(3, 3)
        m.set(0, 0, 1)
        m.set(0, 1, 2)
        m.set(0, 2, 3)
        m.set(1, 0, 4)
        m.set(1, 1, 5)
        m.set(1, 2, 6)
        m.set(2, 0, 7)
        m.set(2, 1, 8)
        m.set(2, 2, 9)
        self.assertEqual(m.det(), 0)
开发者ID:liquidmetal,项目名称:linear-algebra,代码行数:67,代码来源:matrix_test.py

示例14: float

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]

#.........这里部分代码省略.........

        and_op = lambda x, y: x and y

        return (functools.reduce(and_op, row_is_ok) and
                functools.reduce(and_op, col_is_ok))

    # For an element of the BTP matrix returns the maximum value
    # to which it can be set within constraints
    def delta(self, i, j):
        row = self.btp_matrix.marginal_row()
        col = self.btp_matrix.marginal_col()
        
        return min(self.source[i] - row[i],
                   self.destination[j] - col[j])

    # Initialization procedure: traverse the matrix in a random
    # order and assign, within constraints, a portion of the maximum
    # possible value. The portion depends on the value of the depth parameter
    def init(self, index_seq=[], depth=0):
        if index_seq:
            traversal = index_seq
        else:
            traversal = self.random_traversal()

        # Choose portion
        if depth:
            portion = random.uniform(0.0, 1.0)
        else:
            portion = 1.0

        # Assign always the maximum possible value
        for (i, j) in traversal:
            value = self.btp_matrix.at(i, j) + self.delta(i, j) * portion
            self.btp_matrix.set(i, j, value)

        if depth:
            self.init(traversal, depth - 1)
            return

        if not self.check_constraints():
            print sum(self.btp_matrix.marginal_row())
            print sum(self.btp_matrix.marginal_col())
            raise BTPConstraintViolationException()

    # Mutation operator. If parameter boundary is True an element
    # is changed to its maximum allowed value. Otherwise, it is changed
    # to a portion of its maximum allowed value
    def fixed_mutation(self, boundary=True):
        cell = (i, j) = self.random_element()

        # If boundary mutation set to maximum, otherwise set to a portion
        if boundary:
            portion = 1.0
            depth = 0
            traversal = self.random_traversal()
            traversal.remove(cell)
        else:
            portion = random.uniform(0.0, 1.0)
            depth = 3
            traversal = []
        
        self.btp_matrix.set_all(0)
        new_value = self.delta(i, j) * portion
        self.btp_matrix.set(i, j, new_value)

        # Rerun initialization with zero depth, ignoring that element
开发者ID:Pikecillo,项目名称:e-pro,代码行数:70,代码来源:btp_chromosome.py

示例15: test_set_value

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import set [as 别名]
 def test_set_value(self):
     matrix = Matrix(8, 8)
     matrix.set(8, 8, 15)
     self.assertEquals(matrix.get(8, 8), 15)
开发者ID:rodrigoavalente,项目名称:EditorGrafico,代码行数:6,代码来源:matrix_test.py


注:本文中的matrix.Matrix.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。