本文整理汇总了Python中ert.util.Matrix.rows方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.rows方法的具体用法?Python Matrix.rows怎么用?Python Matrix.rows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ert.util.Matrix
的用法示例。
在下文中一共展示了Matrix.rows方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_transpose
# 需要导入模块: from ert.util import Matrix [as 别名]
# 或者: from ert.util.Matrix import rows [as 别名]
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 )
示例2: test_matrix_copy_column
# 需要导入模块: from ert.util import Matrix [as 别名]
# 或者: from ert.util.Matrix import rows [as 别名]
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] )
示例3: calculatePrincipalComponent
# 需要导入模块: from ert.util import Matrix [as 别名]
# 或者: from ert.util.Matrix import rows [as 别名]
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
示例4: test_matrix
# 需要导入模块: from ert.util import Matrix [as 别名]
# 或者: from ert.util.Matrix import rows [as 别名]
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