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


Python Matrix.pseudoinverse方法代码示例

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


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

示例1: pseudoinverse_with_more_columns_test

# 需要导入模块: from pycast.common.matrix import Matrix [as 别名]
# 或者: from pycast.common.matrix.Matrix import pseudoinverse [as 别名]
    def pseudoinverse_with_more_columns_test(self):
        """Test to calculate the pseudoinverse of a Matrix with more columns than rows."""
        rows = 2
        cols = 4
        data = [
                    [-11,  2, -5.0, 7.0],
                    [  2, -4,  3.4, 5.4]
                ]
        mtrx = Matrix(cols, rows)
        mtrx.initialize(data, rowBased=True)
        # Expected result calculated with scipy
        exRes = [
                    [-0.0541328,   0.02473614],
                    [ 0.00705413, -0.06480734],
                    [-0.02269591,  0.05255596],
                    [ 0.03956448,  0.09492743]
                ]

        res = mtrx.pseudoinverse()
        # Pseudoinverse of a m x n Matrix has to be a n x m Matrix
        self.assertEqual(res.get_width(), rows)
        self.assertEqual(res.get_height(), cols)
        for row in range(cols):
            for col in range(rows):
                self.assertAlmostEqual(exRes[row][col], res.get_value(col, row))
开发者ID:T-002,项目名称:pycast,代码行数:27,代码来源:matrixtest.py

示例2: pseudoinverse_test

# 需要导入模块: from pycast.common.matrix import Matrix [as 别名]
# 或者: from pycast.common.matrix.Matrix import pseudoinverse [as 别名]
    def pseudoinverse_test(self):
        """Test that the pseudoinverse is calculated correctly."""
        rows = 3
        cols = 2
        data = [
                    [1, 2],
                    [2, 4],
                    [3, 6]
                ]
        mtrx = Matrix(cols, rows)
        mtrx.initialize(data, rowBased=True)
        # Expected result calculated with scipy
        exRes = [
                    [0.01428571,  0.02857143,  0.04285714],
                    [0.02857143,  0.05714286,  0.08571429]
                ]

        res = mtrx.pseudoinverse()
        # Pseudoinverse of a m x n Matrix has to be a n x m Matrix
        self.assertEqual(res.get_width(), rows)
        self.assertEqual(res.get_height(), cols)
        for row in range(cols):
            for col in range(rows):
                self.assertAlmostEqual(exRes[row][col], res.get_value(col, row))
开发者ID:T-002,项目名称:pycast,代码行数:26,代码来源:matrixtest.py


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