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


Python util.Matrix类代码示例

本文整理汇总了Python中ert.util.Matrix的典型用法代码示例。如果您正苦于以下问题:Python Matrix类的具体用法?Python Matrix怎么用?Python Matrix使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_matrix_set

 def test_matrix_set(self):
     m1 = Matrix(2,2)
     m1.setAll(99)
     self.assertEqual( 99 , m1[0,0] )
     self.assertEqual( 99 , m1[1,1] )
     m2 = Matrix(2,2 , value = 99)
     self.assertEqual(m1,m2)
开发者ID:agchitu,项目名称:ert,代码行数:7,代码来源:test_matrix.py

示例2: test_copy_equal

    def test_copy_equal(self):
        m1 = Matrix(2, 2)
        m1[0,0] = 0
        m1[0,1] = 1
        m1[1,0] = 2
        m1[1,1] = 3

        m2 = m1.copy( )
        self.assertTrue( m1 == m2 )
开发者ID:agchitu,项目名称:ert,代码行数:9,代码来源:test_matrix.py

示例3: update

def update(rng , mask , module , ert , meas_data , obs_data , state_size):
    S = meas_data.createS()
    R = obs_data.createR()
    dObs = obs_data.createDObs()
    E = obs_data.createE( rng , meas_data.getActiveEnsSize() )
    D = obs_data.createD(E , S)
    obs_data.scale(S , E = E , D = D , R = R , D_obs = dObs)

    A = Matrix(state_size , meas_data.getActiveEnsSize())
    A.randomInit( rng )
    
    module.initUpdate( mask , S , R , dObs , E , D )
    module.updateA( A , S , R , dObs , E , D )
开发者ID:Ensembles,项目名称:ert,代码行数:13,代码来源:test_update.py

示例4: test_str

    def test_str(self):
        m = Matrix(2, 2)
        s = "%s" % m

        m[0,0] = 0
        m[0,1] = 1
        m[1,0] = 2
        m[1,1] = 3
        
        with TestAreaContext("matrix_fprint"):
            with open("matrix.txt", "w") as f:
                m.fprint( f )

            with open("matrix.txt") as f:
                l1 = [ float(x) for x in f.readline().split()]
                l2 = [ float(x) for x in f.readline().split()]

            self.assertEqual( l1[0] , m[0,0])
            self.assertEqual( l1[1] , m[0,1])
            self.assertEqual( l2[0] , m[1,0])
            self.assertEqual( l2[1] , m[1,1])
开发者ID:agchitu,项目名称:ert,代码行数:21,代码来源:test_matrix.py

示例5: test_transpose

    def test_transpose(self):
        m = Matrix(3,2)
        m[0,0] = 0
        m[1,0] = 2
        m[2,0] = 4

        m[0,1] = 1
        m[1,1] = 3
        m[2,1] = 5
        
        mt = m.transpose( ) 
        
        self.assertEqual(m[0,0] , 0)
        self.assertEqual(m[1,0] , 2)
        self.assertEqual(m[2,0] , 4)

        self.assertEqual(m[0,1] , 1)
        self.assertEqual(m[1,1] , 3)
        self.assertEqual(m[2,1] , 5)

        self.assertEqual( mt.rows() , m.columns())
        self.assertEqual( mt.columns() , m.rows())
        self.assertEqual(mt[0,0] , 0)
        self.assertEqual(mt[1,0] , 1)

        self.assertEqual(mt[0,1] , 2)
        self.assertEqual(mt[1,1] , 3)

        self.assertEqual(mt[0,2] , 4)
        self.assertEqual(mt[1,2] , 5)
        
        m.transpose( inplace = True )
        self.assertEqual( m , mt )
开发者ID:agchitu,项目名称:ert,代码行数:33,代码来源:test_matrix.py

示例6: test_matrix

    def test_matrix(self):
        m = Matrix(2, 3)

        self.assertEqual(m.rows(), 2)
        self.assertEqual(m.columns(), 3)

        self.assertEqual(m[(0, 0)], 0)

        m[(1, 1)] = 1.5
        self.assertEqual(m[(1, 1)], 1.5)

        m[1,0] = 5
        self.assertEqual(m[1, 0], 5)

        with self.assertRaises(TypeError):
            m[5] = 5

        with self.assertRaises(IndexError):
            m[2, 0] = 0

        with self.assertRaises(IndexError):
            m[0, 3] = 0
开发者ID:agchitu,项目名称:ert,代码行数:22,代码来源:test_matrix.py

示例7: test_matmul

    def test_matmul(self):
        m1 = Matrix(3,3)
        m2 = Matrix(2,2)

        with self.assertRaises(ValueError):
            Matrix.matmul( m1 , m2 )

        m = Matrix(3,2)
        m[0,0] = 0
        m[1,0] = 2
        m[2,0] = 4

        m[0,1] = 1
        m[1,1] = 3
        m[2,1] = 5
        
        mt = m.transpose( ) 

        m2 = Matrix.matmul( m , mt )
        
        self.assertEqual( m2[0,0] , 1  )
        self.assertEqual( m2[1,1] , 13 )
        self.assertEqual( m2[2,2] , 41 )
开发者ID:agchitu,项目名称:ert,代码行数:23,代码来源:test_matrix.py

示例8: test_sub_copy

    def test_sub_copy(self):
        m1 = Matrix(3,3)
        rng = RandomNumberGenerator(RngAlgTypeEnum.MZRAN, RngInitModeEnum.INIT_DEFAULT)
        m1.randomInit( rng )

        with self.assertRaises(ValueError):
            m2 = m1.subCopy( 0,0,4,2 )
            
        with self.assertRaises(ValueError):
            m2 = m1.subCopy( 0,0,2,4 )

        with self.assertRaises(ValueError):
            m2 = m1.subCopy( 4,0,1,1 )

        with self.assertRaises(ValueError):
            m2 = m1.subCopy( 0,2,1,2 )

            
        m2 = m1.subCopy( 0,0,2,2 )
        for i in range(2):
            for j in range(2):
                self.assertEqual( m1[i,j] , m2[i,j])
开发者ID:agchitu,项目名称:ert,代码行数:22,代码来源:test_matrix.py

示例9: calculatePrincipalComponent

    def calculatePrincipalComponent(self, fs, local_obsdata, truncation_or_ncomp=3):
        pc = Matrix(1, 1)
        pc_obs = Matrix(1, 1)
        singular_values = DoubleVector()

        state_map = fs.getStateMap()
        ens_mask = BoolVector(False, self.ert().getEnsembleSize())
        state_map.selectMatching(ens_mask, RealizationStateEnum.STATE_HAS_DATA)
        active_list = BoolVector.createActiveList(ens_mask)

        if len(active_list) > 0:
            state = EnkfStateType.FORECAST
            meas_data = MeasData(active_list)
            obs_data = ObsData()

            self.ert().getObservations().getObservationAndMeasureData(fs, local_obsdata, state, active_list, meas_data, obs_data)

            meas_data.deactivateZeroStdSamples(obs_data)

            active_size = len(obs_data)

            if active_size > 0:
                S = meas_data.createS(active_size)
                D_obs = obs_data.createDobs(active_size)

                truncation, ncomp = self.truncationOrNumberOfComponents(truncation_or_ncomp)

                obs_data.scale(S, D_obs=D_obs)
                EnkfLinalg.calculatePrincipalComponents(S, D_obs, truncation, ncomp, pc, pc_obs, singular_values)
                if self.__prior_singular_values is None:
                    self.__prior_singular_values = singular_values
                else:
                    for row in range(pc.rows()):
                        factor = singular_values[row]/self.__prior_singular_values[row]
                        pc.scaleRow( row , factor )
                        pc_obs.scaleRow( row , factor )


                return PcaPlotData(local_obsdata.getName(), pc , pc_obs , singular_values)
        return None
开发者ID:danielfmva,项目名称:ert,代码行数:40,代码来源:pca_fetcher.py

示例10: test_identity

    def test_identity(self):
        m1 = Matrix.identity(1)
        self.assertEqual(m1.rows(), 1)
        self.assertEqual(m1.columns(), 1)
        self.assertEqual(m1[0,0], 1)

        with self.assertRaises(ValueError):
            Matrix.identity(0)
        with self.assertRaises(ValueError):
            Matrix.identity(-3)

        m = Matrix.identity(17)
        self.assertEqual(m.rows(), 17)
        self.assertEqual(m.columns(), 17)
        for i in range(17):
            for j in range(17):
                elt = m[i, j]
                if i == j:
                    self.assertEqual(elt, 1)
                else:
                    self.assertEqual(elt, 0)
开发者ID:Ensembles,项目名称:ert,代码行数:21,代码来源:test_matrix.py

示例11: test_matrix_scale

    def test_matrix_scale(self):
        m = Matrix(2,2 , value = 1)
        m.scaleColumn(0 , 2)
        self.assertEqual(2 , m[0,0])
        self.assertEqual(2 , m[1,0])
        
        m.setAll(1)
        m.scaleRow(1 , 2 )
        self.assertEqual(2 , m[1,0])
        self.assertEqual(2 , m[1,1])

        with self.assertRaises(IndexError):
            m.scaleColumn(10 , 99)
        
        with self.assertRaises(IndexError):
            m.scaleRow(10 , 99)
开发者ID:agchitu,项目名称:ert,代码行数:16,代码来源:test_matrix.py

示例12: test_matrix_copy_column

    def test_matrix_copy_column(self):
        m = Matrix(10,2)
        rng = RandomNumberGenerator(RngAlgTypeEnum.MZRAN, RngInitModeEnum.INIT_DEFAULT)
        m.randomInit( rng )

        with self.assertRaises(ValueError):
            m.copyColumn(0,2)

        with self.assertRaises(ValueError):
            m.copyColumn(2,0)

        with self.assertRaises(ValueError):
            m.copyColumn(-2,0)
            
        m.copyColumn(1, 0)
        for i in range(m.rows()):
            self.assertEqual( m[i,0] , m[i,1] )
开发者ID:agchitu,项目名称:ert,代码行数:17,代码来源:test_matrix.py

示例13: test_matrix_random_init

 def test_matrix_random_init(self):
     m = Matrix(10,10)
     rng = RandomNumberGenerator(RngAlgTypeEnum.MZRAN, RngInitModeEnum.INIT_DEFAULT)
     m.randomInit( rng )
开发者ID:agchitu,项目名称:ert,代码行数:4,代码来源:test_matrix.py

示例14: test_csv

 def test_csv(self):
     m = Matrix(2, 2)
     m[0, 0] = 2
     m[1, 1] = 4
     with TestAreaContext("matrix_csv"):
         m.dumpCSV("matrix.csv")
开发者ID:agchitu,项目名称:ert,代码行数:6,代码来源:test_matrix.py

示例15: _n_identity_mcs

 def _n_identity_mcs(self, n=6,s=3):
     """return n copies of the identity matrix on s*s elts"""
     return tuple([Matrix.identity(s) for i in range(n)])
开发者ID:Ensembles,项目名称:ert,代码行数:3,代码来源:test_analysis_module.py


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