本文整理汇总了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
示例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()'
示例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)
示例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))
示例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)
示例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})