本文整理汇总了Python中sympy.Basic类的典型用法代码示例。如果您正苦于以下问题:Python Basic类的具体用法?Python Basic怎么用?Python Basic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Basic类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: my_compare
def my_compare(a, b):
main_var = s
p1, p2, p3 = Wild("p1"), Wild("p2"), Wild("p3")
r_a = a.match(p1 * s**p3)
r_b = b.match(p1 * s**p3)
if r_a is not None and r_b is not None:
c = Basic.compare(r_a[p3], r_b[p3])
if c!=0:
return c
return Basic._compare_pretty(a,b)
开发者ID:ryanGT,项目名称:research,代码行数:11,代码来源:two_dof_utils.py
示例2: __new__
def __new__(cls, i, j):
i, j = map(sympify, (i, j))
r = cls.canonize(i, j)
if isinstance(r, Basic):
return r
obj = Basic.__new__(cls, i, j, commutative=True)
return obj
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:7,代码来源:secondquant.py
示例3: __new__
def __new__(cls, dimension):
dimension = sympify(dimension)
r = cls.eval(dimension)
if isinstance(r, Basic):
return r
obj = Basic.__new__(cls, dimension, **{'commutative': False})
return obj
开发者ID:ArchKaine,项目名称:sympy,代码行数:7,代码来源:hilbert.py
示例4: __new__
def __new__ (cls, arg, **options):
# print "Inverse(", arg, ")"
# print INVERTIBLE
if isinstance(arg, Inverse):
return arg.args[0]
if arg.is_Number:
return 1 / arg
arg_rank = expr_rank(arg)
if arg_rank == 1:
raise NotInvertibleError
if is_one(arg):
return arg
if is_zero(arg):
raise NotInvertibleError
# FIXME: Funky case trying to catch lower triangular or diagonal
# muls like T(P_0)*A*P_0
if arg in INVERTIBLE:
pass
elif isinstance(arg, TensorExpr) and not arg.has_inverse:
raise NotInvertibleError
elif isinstance(arg, Mul):
if arg.args[0] == S(-1):
return - Inverse(reduce(operator.mul, arg.args[1:]))
if not expr_invertible(arg):
raise NotInvertibleError
options['commutative'] = arg.is_commutative
return Basic.__new__(cls, arg, **options)
开发者ID:VictorEijkhout,项目名称:ignition,代码行数:30,代码来源:basic_operators.py
示例5: __new__
def __new__(cls, sym, dist):
sym = sympify(sym)
if isinstance(dist, SingleContinuousDistribution):
return SingleContinuousPSpace(sym, dist)
if isinstance(dist, SingleDiscreteDistribution):
return SingleDiscretePSpace(sym, dist)
return Basic.__new__(cls, sym, dist)
开发者ID:normalhuman,项目名称:sympy,代码行数:7,代码来源:joint_rv.py
示例6: _new
def _new(cls, *args, **kwargs):
if len(args)==1 and isinstance(args[0], ImmutableMatrix):
return args[0]
rows, cols, mat = MatrixBase._handle_creation_inputs(*args, **kwargs)
shape = Tuple(rows, cols)
mat = Tuple(*mat)
return Basic.__new__(cls, shape, mat)
开发者ID:ENuge,项目名称:sympy,代码行数:7,代码来源:immutable_matrix.py
示例7: __new__
def __new__(cls, iterable=None, shape=None, **kwargs):
from sympy.utilities.iterables import flatten
shape, flat_list = cls._handle_ndarray_creation_inputs(iterable, shape, **kwargs)
shape = Tuple(*map(_sympify, shape))
loop_size = functools.reduce(lambda x,y: x*y, shape) if shape else 0
# Sparse array:
if isinstance(flat_list, (dict, Dict)):
sparse_array = Dict(flat_list)
else:
sparse_array = {}
for i, el in enumerate(flatten(flat_list)):
if el != 0:
sparse_array[i] = _sympify(el)
sparse_array = Dict(sparse_array)
self = Basic.__new__(cls, sparse_array, shape, **kwargs)
self._shape = shape
self._rank = len(shape)
self._loop_size = loop_size
self._sparse_array = sparse_array
return self
开发者ID:jarthurgross,项目名称:sympy,代码行数:25,代码来源:sparse_ndim_array.py
示例8: sample2d
def sample2d(f, x_args):
"""
Samples a 2d function f over specified intervals and returns two
arrays (X, Y) suitable for plotting with matlab (matplotlib)
syntax. See examples\mplot2d.py.
f is a function of one variable, such as x**2.
x_args is an interval given in the form (var, min, max, n)
"""
try:
f = Basic.sympify(f)
except:
raise ValueError("f could not be interpretted as a SymPy function")
try:
x, x_min, x_max, x_n = x_args
except:
raise ValueError("x_args must be a tuple of the form (var, min, max, n)")
x_l = float(x_max - x_min)
x_d = x_l/float(x_n)
X = arange(float(x_min), float(x_max)+x_d, x_d)
Y = empty(len(X))
for i in range(len(X)):
try:
Y[i] = float(f.subs(x, X[i]))
except:
Y[i] = None
return X, Y
开发者ID:certik,项目名称:sympy-oldcore,代码行数:29,代码来源:sample.py
示例9: __new__
def __new__(cls, dimension):
dimension = sympify(dimension)
r = cls.eval(dimension)
if isinstance(r, Basic):
return r
obj = Basic.__new__(cls, dimension)
return obj
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:7,代码来源:hilbert.py
示例10: __new__
def __new__(cls, M):
if not isinstance(M, Matrix):
M = Matrix(M)
data = Tuple(*M._mat)
shape = Tuple(*sympify(M.shape))
obj = Basic.__new__(cls, data, shape)
obj._mat = M
return obj
开发者ID:aeberspaecher,项目名称:sympy,代码行数:8,代码来源:blockmatrix.py
示例11: __new__
def __new__(cls, mat):
if not mat.is_Matrix:
raise TypeError("input to Trace, %s, is not a matrix" % str(mat))
if not mat.is_square:
raise ShapeError("Trace of a non-square matrix")
return Basic.__new__(cls, mat)
开发者ID:mattpap,项目名称:sympy,代码行数:8,代码来源:trace.py
示例12: _new
def _new(cls, *args, **kwargs):
if len(args) == 1 and isinstance(args[0], ImmutableMatrix):
return args[0]
rows, cols, flat_list = MatrixBase._handle_creation_inputs(*args, **kwargs)
rows = Integer(rows)
cols = Integer(cols)
mat = Tuple(*flat_list)
return Basic.__new__(cls, rows, cols, mat)
开发者ID:hastebrot,项目名称:sympy,代码行数:8,代码来源:immutable.py
示例13: __new__
def __new__(cls, *args):
# args should be a tuple - a variable length argument list
obj = Basic.__new__(cls, *args)
obj._circuit = Mul(*args)
obj._rules = generate_gate_rules(args)
obj._eq_ids = generate_equivalent_ids(args)
return obj
开发者ID:Acebulf,项目名称:sympy,代码行数:8,代码来源:identitysearch.py
示例14: __new__
def __new__(cls, mat):
if not isinstance(mat, Matrix):
mat = Matrix(mat)
data = Tuple(*mat.mat)
shape = Tuple(*sympify(mat.shape))
obj = Basic.__new__(cls, data, shape)
obj.mat = mat
return obj
开发者ID:BDGLunde,项目名称:sympy,代码行数:8,代码来源:blockmatrix.py
示例15: set_v_max
def set_v_max(self, v_max):
if v_max is None:
self._v_max = None
return
try:
self._v_max = Basic.sympify(v_max)
float(self._v_max.evalf())
except:
raise ValueError("v_max could not be interpreted as a number.")
开发者ID:certik,项目名称:sympy-oldcore,代码行数:9,代码来源:plot_interval.py
示例16: test_expr_fns
def test_expr_fns():
from sympy.strategies.rl import rebuild
from sympy import Add
x, y = map(Symbol, 'xy')
expr = x + y**3
e = bottom_up(lambda x: x + 1, expr_fns)(expr)
b = bottom_up(lambda x: Basic.__new__(Add, x, 1), basic_fns)(expr)
assert rebuild(b) == e
开发者ID:AALEKH,项目名称:sympy,代码行数:9,代码来源:test_traverse.py
示例17: __new__
def __new__(cls, pspace, symbol=None):
if symbol is None:
# Allow single arg, representing pspace == PSpace()
pspace, symbol = PSpace(), pspace
if not isinstance(symbol, Symbol):
raise TypeError("symbol should be of type Symbol")
if not isinstance(pspace, PSpace):
raise TypeError("pspace variable should be of type PSpace")
return Basic.__new__(cls, pspace, symbol)
开发者ID:BiosPsucheZoe,项目名称:sympy,代码行数:9,代码来源:rv.py
示例18: set_v_min
def set_v_min(self, v_min):
if v_min is None:
self._v_min = None
return
try:
self._v_min = Basic.sympify(v_min)
float(self._v_min.evalf())
except:
raise ValueError("v_min could not be interpreted as a number.")
开发者ID:certik,项目名称:sympy-oldcore,代码行数:9,代码来源:plot_interval.py
示例19: __new__
def __new__(cls, num, denom=None):
obj = Basic.__new__(cls)
if denom is None:
if isinstance(num, str):
obj.p, obj.q = parse_rational(num)
else:
obj.p = num
obj.q = denom
return obj
开发者ID:kwangkim,项目名称:fourU,代码行数:9,代码来源:utils.py
示例20: __new__
def __new__(cls, sym, dist):
if isinstance(dist, SingleContinuousDistribution):
return SingleContinuousPSpace(sym, dist)
if isinstance(dist, SingleDiscreteDistribution):
return SingleDiscretePSpace(sym, dist)
if isinstance(sym, string_types):
sym = Symbol(sym)
if not isinstance(sym, Symbol):
raise TypeError("s should have been string or Symbol")
return Basic.__new__(cls, sym, dist)
开发者ID:asmeurer,项目名称:sympy,代码行数:10,代码来源:joint_rv.py
注:本文中的sympy.Basic类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论