本文整理汇总了Python中matrix.Matrix.fill方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.fill方法的具体用法?Python Matrix.fill怎么用?Python Matrix.fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.fill方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_matrix_fill
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import fill [as 别名]
def test_matrix_fill():
m, n = 5, 5
matrix = Matrix(m, n)
matrix.colorize(2, 0, 'X')
matrix.colorize(2, 4, 'X')
matrix.colorize(0, 2, 'X')
matrix.colorize(4, 2, 'X')
matrix.fill(2, 2, 'X')
assert ['X'] * 5 == matrix[2]
for i in range(0, 5):
matrix[i][2] == 'X'
示例2: __find_eigenvector
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import fill [as 别名]
def __find_eigenvector(self, eig_val, prec, relax_coef):
is_complex = type(eig_val) is complex
e_lam = Matrix.identity(self.mtrx.size)
e_lam *= eig_val
a = GaussMethod.get_inverse_matrix(self.mtrx - e_lam)
x_prev = Matrix((self.mtrx.size[0], 1))
if is_complex:
x_prev.fill(*[complex(random.randint(1, 100), random.randint(1, 100)) for _ in range(x_prev.size[0])])
else:
x_prev.fill(*[random.randint(1, 100) for _ in range(x_prev.size[0])])
x_cur = (a * x_prev).normalize()
# method does not always converge,
# so use successive over-relaxation (SOR) method
relax_coef *= 0.1
while (x_cur - x_prev).norm_inf() > prec:
x_prev = x_cur
x_cur = (a * x_prev)
x_cur *= relax_coef
tmp_x = x_prev.copy()
tmp_x *= 1 - relax_coef
x_cur = x_cur + tmp_x
x_cur = x_cur.normalize()
return x_cur
示例3: init
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import fill [as 别名]
class MatrixParser:
def init(self, m, n):
m, n = int(m), int(n)
self.matrix = Matrix(m, n)
def clean(self):
self.matrix.clean()
def colorize(self, x, y, color):
# Humanaze
x, y = int(x), int(y)
x, y = x - 1, y - 1
self.matrix.colorize(x, y, color)
def vcolorize(self, x, y1, y2, color):
x, y1, y2 = int(x), int(y1), int(y2)
x, y1, y2 = x - 1, y1 - 1, y2 - 1
self.matrix.vcolorize(x, y1, y2, color)
def hcolorize(self, x1, x2, y, color):
y, x1, x2 = int(y), int(x1), int(x2)
y, x1, x2 = y - 1, x1 - 1, x2 - 1
self.matrix.hcolorize(y, x1, x2, color)
def fill(self, x, y, color):
x, y = int(x), int(y)
x, y = x - 1, y - 1
self.matrix.fill(x, y, color)
def rect(self, x1, y1, x2, y2, color):
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
x1, y1, x2, y2 = x1 - 1, y1 - 1, x2 - 1, y2 - 1
self.matrix.rect(x1, y1, x2, y2, color)
def replace(self, x, y, color):
x, y = int(x), int(y)
x, y = x - 1, y - 1
self.matrix.replace(x, y, color)
def save(self, name):
self.matrix.save(name)
def parse(self, command):
command, *args = command.split()
method = self._REGISTER.get(command)
if method:
method(self, *args)
_REGISTER = {
'I': init,
'C': clean,
'L': colorize,
'V': vcolorize,
'H': hcolorize,
'Q': fill,
'F': replace,
'K': rect,
'S': save
}