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


Python Matrix.householder方法代码示例

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


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

示例1: householder_test

# 需要导入模块: from pycast.common.matrix import Matrix [as 别名]
# 或者: from pycast.common.matrix.Matrix import householder [as 别名]
    def householder_test(self):
        """Test the householder transformation to get a matrix in bidiagonalization."""
        # set up test
        c = [
                [4, 3, 0],
                [2, 1, 2],
                [4, 4, 0]
        ]
        matrix = Matrix(3, 3)
        matrix.initialize(c, rowBased=True)

        # execute householder transformation
        u, bidiag, v = matrix.householder()

        # expect, that multiplication works correctly.
        res = u * bidiag * v
        # res should be equal with c (except some rounding errors)
        for row in range(res.get_height()):
            for col in range(res.get_width()):
                self.assertAlmostEqual(res.get_value(col, row), c[row][col], PRECISION)
        # bidiag matrix should have 0 values below the diagonal
        self.assertAlmostEqual(bidiag.get_value(0, 1), 0, PRECISION)
        self.assertAlmostEqual(bidiag.get_value(0, 2), 0, PRECISION)
        self.assertAlmostEqual(bidiag.get_value(1, 2), 0, PRECISION)

        self.assertAlmostEqual(bidiag.get_value(2, 0), 0, PRECISION)
开发者ID:T-002,项目名称:pycast,代码行数:28,代码来源:matrixtest.py

示例2: householder_with_zero_column_test

# 需要导入模块: from pycast.common.matrix import Matrix [as 别名]
# 或者: from pycast.common.matrix.Matrix import householder [as 别名]
    def householder_with_zero_column_test(self):
        """Test the householder transformation of a Matrix with a 0 column

        All values of the 2nd column are 0."""
        # set up test
        c = [
                [3, 0, 3, 2],
                [0, 0, 5, 6],
                [4, 0, 4, 7],
                [8, 0, 3, 9]
            ]
        matrix = Matrix(4, 4)
        matrix.initialize(c, rowBased=True)

        # execute householder transformation
        u, bidiag, v = matrix.householder()

        # expect, that multiplication works correctly.
        res = u * bidiag * v
        # res should be equal with c (except some rounding errors)
        for row in range(res.get_height()):
            for col in range(res.get_width()):
                self.assertAlmostEqual(res.get_value(col, row), c[row][col], PRECISION)
开发者ID:T-002,项目名称:pycast,代码行数:25,代码来源:matrixtest.py


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