本文整理汇总了Python中sympy.Matrix.row方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.row方法的具体用法?Python Matrix.row怎么用?Python Matrix.row使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Matrix
的用法示例。
在下文中一共展示了Matrix.row方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_col_row
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import row [as 别名]
def test_col_row():
x, y = symbols("xy")
M = Matrix([[x,0,0],
[0,y,0]])
M.row(1,lambda x,i: x+i+1)
assert M == Matrix([[x,0,0],
[1,y+2,3]])
M.col(0,lambda x,i: x+y**i)
assert M == Matrix([[x+1,0,0],
[1+y,y+2,3]])
示例2: test_col_row
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import row [as 别名]
def test_col_row():
x, y = symbols("x y")
M = Matrix([[x,0,0],
[0,y,0]])
M.row(1,lambda r, j: r+j+1)
assert M == Matrix([[x,0,0],
[1,y+2,3]])
M.col(0,lambda c, j: c+y**j)
assert M == Matrix([[x+1,0,0],
[1+y,y+2,3]])
示例3: __init__
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import row [as 别名]
def __init__(
self,
a_choice: int,
b_choice: int,
payoff_matrix: Matrix,
previous_step: Optional):
self.step_number = 1
if previous_step:
self.step_number = previous_step.step_number + 1
self.a_choice = a_choice
self.b_choice = b_choice
self.a_gain = payoff_matrix.col(self.b_choice).T.tolist()[0]
self.b_gain = payoff_matrix.row(self.a_choice).tolist()[0]
self.min_upper_game_cost = self.upper_game_cost
self.max_lower_game_cost = self.lower_game_cost
if previous_step:
self.a_gain = [sum(x) for x in
zip(self.a_gain, previous_step.a_gain)]
self.b_gain = [sum(x) for x in
zip(self.b_gain, previous_step.b_gain)]
self.min_upper_game_cost = min(
(self.upper_game_cost, previous_step.min_upper_game_cost))
self.max_lower_game_cost = max(
(self.lower_game_cost, previous_step.max_lower_game_cost))
示例4: _find_extremums_by_axis
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import row [as 别名]
def _find_extremums_by_axis(self, payoff_matrix: Matrix, axis: str, fn: Callable) -> List[Tuple]:
if axis == 'columns':
lines = [payoff_matrix.col(j).T.tolist()[0] for j in range(payoff_matrix.cols)]
elif axis == 'rows':
lines = [payoff_matrix.row(i).tolist()[0] for i in range(payoff_matrix.rows)]
else:
raise Exception("Axis should be 'rows' or 'columns'")
return [(fn(line), line.index(fn(line))) for line in lines]
示例5: SimpleLieAlgebra
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import row [as 别名]
class SimpleLieAlgebra(Algebra):
def __init__(self, cartan_matrix):
self.cartan_matrix = cartan_matrix
self.rank = cartan_matrix.rows
self.simple_roots = Matrix(self.construct_simple_roots())
pcoeff, self.levels = self.positive_root_coeffcients()
coeff = (pcoeff + [[0] * self.rank] * self.rank +
[[-c for c in e] for e in pcoeff])
self.root_coefficients = Matrix(coeff)
self.roots = self.root_coefficients * self.simple_roots
self.fund_weights = self.cartan_matrix.inv() * self.simple_roots
self.proots = Matrix(self.roots.tolist()[:len(pcoeff)])
self.delta = sum((self.proots.row(i) for i in xrange(len(pcoeff))),
zeros(1, self.rank)) / 2
def index(self, highest):
return (self.quad_casimir(highest) * self.dimension(highest) /
self.roots.rows)
def dimension(self, highest):
d = 1
highest_weight = Matrix([highest]) * self.fund_weights
for i in xrange(self.proots.rows):
alpha = self.proots.row(i)
d *= (1 + alpha.dot(highest_weight) / alpha.dot(self.delta))
return d
def quad_casimir(self, highest):
highest_weight = Matrix([highest]) * self.fund_weights
return highest_weight.norm()**2 + 2 * highest_weight.dot(self.delta)
def weights(self, highest):
current_weights = [Weight(ImmutableMatrix([(0,) * len(highest)]),
ImmutableMatrix([highest]),
self.cartan_matrix)]
weights = [Matrix([highest]) * self.fund_weights]
highest_weight = weights[0]
hd = highest_weight + 2 * self.delta
d = {highest_weight.as_immutable(): 1}
depth = 0
while True:
depth += 1
descendants = {}
degtocalc = []
for weight in current_weights:
for r, i, pi in weight.descendants():
if r in descendants:
descendants[r][i] = pi
if r not in degtocalc:
degtocalc.append(r)
else:
descendants[r] = ([0] * i + [pi] +
[0] * (self.rank - 1 - i))
if not descendants:
break
current_weights = [None] * len(descendants)
for i, r in enumerate(descendants):
weight = (Matrix([r]) * self.fund_weights).as_immutable()
if r in degtocalc:
# Freudenthal recursion formula
deg = 0
denom = (hd + weight).dot(highest_weight - weight)
for j in xrange(self.proots.rows):
alpha = self.proots.row(j)
level = self.levels[j]
tw = weight
# TODO: any root can be a simple root so that no two roots are parallel.
# that means once we find k for a difference, no other root must we find.
# moreover, we do NOT compare all the element. first, we just see some
# non-zero element and devide it by the one of alpha. if k < depth / level,
# then we compare all the element. this reduces #(summing)
for k in xrange(1, depth / level + 1):
tw += alpha
if tw in d:
deg += d[tw] * tw.dot(alpha)
deg = 2 * deg / denom
else:
deg = 1
d[weight] = deg
for j in xrange(deg):
weights.append(weight)
current_weights[i] = Weight(ImmutableMatrix([descendants[r]]),
r, self.cartan_matrix)
return ImmutableMatrix(weights)
#.........这里部分代码省略.........