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


Python Mul.append方法代码示例

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


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

示例1: linear_expand

# 需要导入模块: from sympy import Mul [as 别名]
# 或者: from sympy.Mul import append [as 别名]
def linear_expand(expr):
    """
    If a sympy 'Expr' is of the form:

    expr = expr_0 + expr_1*a_1 + ... + expr_n*a_n

    where all the a_j are noncommuting symbols in basis then

    (expr_0, ..., expr_n) and (1, a_1, ..., a_n) are returned.  Note that
    expr_j*a_j does not have to be of that form, but rather can be any
    Mul with a_j as a factor (it doen not have to be a postmultiplier).
    expr_0 is the scalar part of the expression.
    """
    expr = expand(expr)
    if expr.is_commutative:  # commutative expr only contains expr_0
        return (expr, ), (S.One, )

    if isinstance(expr, Mul):  # expr only contains one term
        (coefs, bases) = expr.args_cnc()
        coefs = Mul(*coefs)
        bases = bases[0]
    elif isinstance(expr, Symbol):  # term is Symbol
        coefs = S.One
        bases = expr
    elif isinstance(expr, Add):  # expr has multiple terms
        coefs = []
        bases = []
        for arg in expr.args:
            term = arg.args_cnc()
            coef = Mul(*term[0])
            base = term[1][0]
            if base in bases:  # increment coefficient of base
                ibase = list(bases).index(base)  # Python 2.5
                coefs[ibase] += coef
            else:  # add base to list
                coefs.append(coef)
                bases.append(base)
    else:
        raise NotImplementedError("linear_expand for type %s" % type(expr))


    if not isinstance(coefs, list):  # convert single coef to list
        coefs = [coefs]
    if not isinstance(bases, list):  # convert single base to list
        bases = [bases]
    coefs = tuple(coefs)
    bases = tuple(bases)
    return coefs, bases
开发者ID:ChaliZhg,项目名称:sympy,代码行数:50,代码来源:ncutil.py

示例2: bilinear_expand

# 需要导入模块: from sympy import Mul [as 别名]
# 或者: from sympy.Mul import append [as 别名]
def bilinear_expand(expr):
    """
    If a sympy 'Expr' is of the form:

    expr = expr_0+expr_1*a_1+...+expr_n*a_n

    where all the a_j are noncommuting symbols in basis then

    (expr_0,...,expr_n) and (1,a_1,...,a_n) are returned.  Note that
    expr_j*a_j does not have to be of that form, but rather can be any
    Mul with a_j as a factor (it doen not have to be a postmultiplier).
    expr_0 is the scalar part of the expression.
    """

    if expr.is_commutative: #commutative expr only contains expr_0
        return((expr,),(ONE,))

    expr = expand(expr)
    if isinstance(expr,Mul): #expr only contains one term
        x = (coefs,bases) = expr.args_cnc()
        coefs = Mul(*coefs)
        bases = Mul(*bases)
    elif isinstance(expr,Symbol): #term is Symbol
        coefs = ONE
        bases = expr
    elif isinstance(expr,Add): #expr has multiple terms
        coefs = []
        bases = []
        for arg in expr.args:
            term = arg.args_cnc()
            coefs.append(Mul(*term[0]))
            bases.append(Mul(*term[1]))

    """
    if not isinstance(coefs,list): #convert single coef to list
        coefs = [coefs]
    if not isinstance(bases,list): #convert single base to list
        bases = [bases]
    """
    coefs = tuple(coefs)
    bases = tuple(bases)
    return(coefs,bases)
开发者ID:Ignat99,项目名称:galgebra,代码行数:44,代码来源:OrthoCopy.py


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