本文整理汇总了Python中sympy.nan方法的典型用法代码示例。如果您正苦于以下问题:Python sympy.nan方法的具体用法?Python sympy.nan怎么用?Python sympy.nan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy
的用法示例。
在下文中一共展示了sympy.nan方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_constants
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import nan [as 别名]
def test_constants():
assert sympify(sympy.E) == E
assert sympy.E == E._sympy_()
assert sympify(sympy.pi) == pi
assert sympy.pi == pi._sympy_()
assert sympify(sympy.GoldenRatio) == GoldenRatio
assert sympy.GoldenRatio == GoldenRatio._sympy_()
assert sympify(sympy.Catalan) == Catalan
assert sympy.Catalan == Catalan._sympy_()
assert sympify(sympy.EulerGamma) == EulerGamma
assert sympy.EulerGamma == EulerGamma._sympy_()
assert sympify(sympy.oo) == oo
assert sympy.oo == oo._sympy_()
assert sympify(sympy.zoo) == zoo
assert sympy.zoo == zoo._sympy_()
assert sympify(sympy.nan) == nan
assert sympy.nan == nan._sympy_()
示例2: __init__
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import nan [as 别名]
def __init__ (self, decl, exists_ok, cache):
'''
:decl: declaration string of variable ('Batch(b):20')
:exists_ok: if declared earlier, nop
:cache: store in `decls` cache
'''
assert isinstance(decl, str)
decl = decl.strip()
m = re.search(DimVar.parse_regexp, decl)
name, sname, val = m.groups()
#print (m.groups())
self._name = name
self._sname = sname if sname is not None else name
self._val = int(val) if val is not None else nan
self._e = Symbol(self._sname)
if self._e in DimVar.decls:
prevd = DimVar.decls[self._e]
if not exists_ok:
raise ValueError(f'DimVar {self._sname} already declared as {prevd._name}({self._e}). Use exists_ok=True to skip check.')
else:
if cache: DimVar.decls[self._e] = self
示例3: len
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import nan [as 别名]
def len(self):
return self._val if (self._val != nan) else None
示例4: __int__
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import nan [as 别名]
def __int__(self):
#print(f'called int {self._val}')
if self._val != nan:
return int(self._val)
else:
#return DimExpr.DEFAULT_VALUE
raise ValueError(f'Cannot cast to integer: Default value of {self._e} not provided')
示例5: __eq__
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import nan [as 别名]
def __eq__(self, d):
#print (f'eq: {self}, {d}')
if isinstance(d, int):
#semantics: any integer matches nan
if self._val == nan: return True
else: return self._val == d
elif isinstance(d, DimExpr):
res = self._e == d._e
#print (res)
return res
else:
return False
示例6: _atan2_0
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import nan [as 别名]
def _atan2_0(X):
"""Like sympy.atan2, but return 0 for x=y=0. Mathematically, the value is
undefined, so sympy returns NaN, but for the sake of the coordinate
conversion, its value doesn't matter. NaNs, however, produce NaNs down the
line.
"""
out = numpy.array([sympy.atan2(X[k, 1], X[k, 0]) for k in range(len(X))])
out[out == sympy.nan] = 0
return out
示例7: q_affine
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import nan [as 别名]
def q_affine(expr, vars):
"""
Return True if ``expr`` is (separately) affine in the variables ``vars``,
False otherwise.
Notes
-----
Exploits:
https://stackoverflow.com/questions/36283548\
/check-if-an-equation-is-linear-for-a-specific-set-of-variables/
"""
vars = as_tuple(vars)
free_symbols = expr.free_symbols
# At this point, `expr` is (separately) affine in the `vars` variables
# if all non-mixed second order derivatives are identically zero.
for x in vars:
if expr is x:
continue
if x not in free_symbols:
# At this point the only hope is that `expr` is constant
return q_constant(expr)
# The vast majority of calls here are incredibly simple tests
# like q_affine(x+1, [x]). Catch these quickly and
# explicitly, instead of calling the very slow function `diff`.
if expr.is_Add and len(expr.args) == 2:
if expr.args[1] is x and expr.args[0].is_Number:
continue
if expr.args[0] is x and expr.args[1].is_Number:
continue
try:
if diff(expr, x) is nan or not Eq(diff(expr, x, x), 0):
return False
except TypeError:
return False
return True