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


Python sympy.srepr方法代码示例

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


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

示例1: test_labelfunc

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import srepr [as 别名]
def test_labelfunc():
    text = dotprint(x + 2, labelfunc=srepr)
    assert "Symbol('x')" in text
    assert "Integer(2)" in text 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:6,代码来源:test_dot.py

示例2: test_hilbert_space

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import srepr [as 别名]
def test_hilbert_space():
    hs = HilbertSpace()
    assert isinstance(hs, HilbertSpace)
    assert sstr(hs) == 'H'
    assert srepr(hs) == 'HilbertSpace()' 
开发者ID:sympsi,项目名称:sympsi,代码行数:7,代码来源:test_hilbert.py

示例3: test_complex_space

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import srepr [as 别名]
def test_complex_space():
    c1 = ComplexSpace(2)
    assert isinstance(c1, ComplexSpace)
    assert c1.dimension == 2
    assert sstr(c1) == 'C(2)'
    assert srepr(c1) == 'ComplexSpace(Integer(2))'

    n = Symbol('n')
    c2 = ComplexSpace(n)
    assert isinstance(c2, ComplexSpace)
    assert c2.dimension == n
    assert sstr(c2) == 'C(n)'
    assert srepr(c2) == "ComplexSpace(Symbol('n'))"
    assert c2.subs(n, 2) == ComplexSpace(2) 
开发者ID:sympsi,项目名称:sympsi,代码行数:16,代码来源:test_hilbert.py

示例4: __eq__

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import srepr [as 别名]
def __eq__(self, other):
        from sympy import srepr
        return (isinstance(other, ParameterExpression)
                and self.parameters == other.parameters
                and srepr(self._symbol_expr) == srepr(other._symbol_expr)) 
开发者ID:Qiskit,项目名称:qiskit-terra,代码行数:7,代码来源:parameterexpression.py

示例5: proper_repr

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import srepr [as 别名]
def proper_repr(value: Any) -> str:
    """Overrides sympy and numpy returning repr strings that don't parse."""

    if isinstance(value, sympy.Basic):
        result = sympy.srepr(value)

        # HACK: work around https://github.com/sympy/sympy/issues/16074
        # (only handles a few cases)
        fixed_tokens = [
            'Symbol', 'pi', 'Mul', 'Pow', 'Add', 'Mod', 'Integer', 'Float',
            'Rational'
        ]
        for token in fixed_tokens:
            result = result.replace(token, 'sympy.' + token)

        return result

    if isinstance(value, np.ndarray):
        return 'np.array({!r}, dtype=np.{})'.format(value.tolist(), value.dtype)

    if isinstance(value, pd.MultiIndex):
        return (f'pd.MultiIndex.from_tuples({repr(list(value))}, '
                f'names={repr(list(value.names))})')

    if isinstance(value, pd.Index):
        return (f'pd.Index({repr(list(value))}, '
                f'name={repr(value.name)}, '
                f'dtype={repr(str(value.dtype))})')

    if isinstance(value, pd.DataFrame):
        cols = [value[col].tolist() for col in value.columns]
        rows = list(zip(*cols))
        return (f'pd.DataFrame('
                f'\n    columns={proper_repr(value.columns)}, '
                f'\n    index={proper_repr(value.index)}, '
                f'\n    data={repr(rows)}'
                f'\n)')

    return repr(value) 
开发者ID:quantumlib,项目名称:Cirq,代码行数:41,代码来源:_compat.py

示例6: substitute_with_eval

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import srepr [as 别名]
def substitute_with_eval(expression: sympy.Expr,
                         substitutions: Dict[str, Union[sympy.Expr, numpy.ndarray, str]]) -> sympy.Expr:
    """Substitutes only sympy.Symbols. Workaround for numpy like array behaviour. ~Factor 3 slower compared to subs"""
    substitutions = {k: v if isinstance(v, sympy.Expr) else sympify(v)
                     for k, v in substitutions.items()}

    for symbol in get_free_symbols(expression):
        symbol_name = str(symbol)
        if symbol_name not in substitutions:
            substitutions[symbol_name] = symbol

    string_representation = sympy.srepr(expression)
    return eval(string_representation, sympy.__dict__, {'Symbol': substitutions.__getitem__,
                                                        'Mul': numpy_compatible_mul}) 
开发者ID:qutech,项目名称:qupulse,代码行数:16,代码来源:sympy.py


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