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


Python Matrix.xreplace方法代码示例

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


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

示例1: solve_for_sub_subspace

# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import xreplace [as 别名]
def solve_for_sub_subspace(matrixrows, sub_sub_space,
                           coeffs, cvector,
                           iofvars, subs_rules,
                           fvargen, newfvars, tempgen, tempvars):
    sspacedict = dict(zip(sub_sub_space, range(len(sub_sub_space))))
    length = len(sub_sub_space)
    augmatrixrows = []
    rownumstore = [] #for debugging
    for rownum, row in matrixrows.items():
        if row and row[0][0] in sub_sub_space:
            augmatrixrows.append(length*[0]+[cvector[rownum]])
            rownumstore.append(rownum)
            for el in row:
                augmatrixrows[-1][sspacedict[el[0]]] = el[1]
    fvars = [coeffs[ind] for ind in sub_sub_space]
    augmatrix = Matrix(augmatrixrows)
    oldfvars = []
    if iofvars:
        #ipdb.set_trace()
        atoms = augmatrix.atoms(sympy.Symbol)
        for iofvar in subs_rules:
            if iofvar in atoms:
                augmatrix = augmatrix.xreplace({iofvar: subs_rules[iofvar]})
        atoms = augmatrix.atoms(sympy.Symbol)
        for iofvar in iofvars:
            if iofvar not in subs_rules and iofvar in atoms:
                fvars.append(iofvar)
                oldfvars.append(iofvar)
                augmatrix = augmatrix.col_insert(-1, sympy.zeros(augmatrix.rows,1))
                for row_ind in range(len(augmatrix[:,0])):
                    coeff_val = -sympy.expand(augmatrix[row_ind,-1]).coeff(iofvar)
                    augmatrix[row_ind,-2] = coeff_val
                    augmatrix[row_ind,-1] += coeff_val*iofvar
    sols, success = linear_solve(augmatrix, fvars, iofvars, fvargen, newfvars, tempgen, tempvars, len(oldfvars))
    if not success:
        print(repr(augmatrix))
        print(fvars)
        print(rownumstore)
        print(iofvars)
        print(subs_rules)
        raise ValueError("Failure. No solutions.")
    for oldfvar in oldfvars:
        if oldfvar in sols:
            subs_rules.update({var: rule.xreplace({oldfvar: sols[oldfvar]})
                          for var, rule in subs_rules.items()})
            subs_rules[oldfvar] = default_simplify(sols[oldfvar])
    return sols
开发者ID:MooVI,项目名称:commutator,代码行数:49,代码来源:para_commutator.py


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