本文整理汇总了Python中numexpr.evaluate方法的典型用法代码示例。如果您正苦于以下问题:Python numexpr.evaluate方法的具体用法?Python numexpr.evaluate怎么用?Python numexpr.evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numexpr
的用法示例。
在下文中一共展示了numexpr.evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evaluate
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def evaluate(self):
"""Run the engine on the expression
This method performs alignment which is necessary no matter what engine
is being used, thus its implementation is in the base class.
Returns
-------
obj : object
The result of the passed expression.
"""
if not self._is_aligned:
self.result_type, self.aligned_axes = _align(self.expr.terms)
# make sure no names in resolvers and locals/globals clash
res = self._evaluate()
return _reconstruct_object(self.result_type, res, self.aligned_axes,
self.expr.terms.return_type)
示例2: _evaluate
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def _evaluate(self):
import numexpr as ne
# convert the expression to a valid numexpr expression
s = self.convert()
try:
env = self.expr.env
scope = env.full_scope
truediv = scope['truediv']
_check_ne_builtin_clash(self.expr)
return ne.evaluate(s, local_dict=scope, truediv=truediv)
except KeyError as e:
# python 3 compat kludge
try:
msg = e.message
except AttributeError:
msg = compat.text_type(e)
raise UndefinedVariableError(msg)
示例3: evaluate
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def evaluate(op, op_str, a, b, use_numexpr=True,
**eval_kwargs):
""" evaluate and return the expression of the op on a and b
Parameters
----------
op : the actual operand
op_str: the string version of the op
a : left operand
b : right operand
use_numexpr : whether to try to use numexpr (default True)
"""
use_numexpr = use_numexpr and _bool_arith_check(op_str, a, b)
if use_numexpr:
return _evaluate(op, op_str, a, b, **eval_kwargs)
return _evaluate_standard(op, op_str, a, b)
示例4: planck_f
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def planck_f(f, T):
"""Planck law expressed in frequency.
If more than 10⁵ resulting radiances, uses numexpr.
:param f: Frequency. Quantity in [Hz]
:param T: Temperature. Quantity in [K]
"""
# try:
# f = f.astype(numpy.float64)
# except AttributeError:
# pass
if (f.size * T.size) > 1e5:
return numexpr.evaluate("(2 * h * f**3) / (c**2) * "
"1 / (exp((h*f)/(k*T)) - 1)") * (
radiance_units["si"])
return ((2 * ureg.h * f**3) / (ureg.c ** 2) *
1 / (numpy.exp(((ureg.h * f) / (ureg.k * T)).to("1")) - 1)).to(
ureg.W / (ureg.m**2 * ureg.sr * ureg.Hz))
示例5: execute
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def execute(cls, ctx, op):
chunk = op.outputs[0]
inputs = as_same_device([ctx[c.key] for c in op.inputs], device=op.device)
for c, i in zip(op.inputs, inputs):
exec('V_' + c.key + ' = i')
expr = _evaluate(chunk)
if cls._lock is not None:
cls._lock.acquire()
try:
res = ne.evaluate(expr)
finally:
if cls._lock is not None:
cls._lock.release()
res = _maybe_keepdims(chunk, res)
if chunk.ndim == 0 and res.ndim == 1 and res.size == 0:
res = res.dtype.type(0)
ctx[chunk.key] = res
示例6: fields
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def fields(x,y,z, kx, ky, kz, B0):
k1 = -B0*kx/ky
k2 = -B0*kz/ky
kx_x = kx*x
ky_y = ky*y
kz_z = kz*z
cosx = np.cos(kx_x)
sinhy = np.sinh(ky_y)
cosz = np.cos(kz_z)
Bx = k1*np.sin(kx_x)*sinhy*cosz #// here kx is only real
By = B0*cosx*np.cosh(ky_y)*cosz
Bz = k2*cosx*sinhy*np.sin(kz_z)
#Bx = ne.evaluate("k1*sin(kx*x)*sinhy*cosz")
#By = ne.evaluate("B0*cosx*cosh(ky*y)*cosz")
#Bz = ne.evaluate("k2*cosx*sinhy*sin(kz*z)")
return Bx, By, Bz
示例7: sym_kernel
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def sym_kernel(self, ijk2, hxyz):
i2 = ijk2[0]
j2 = ijk2[1]
k2 = ijk2[2]
hx = hxyz[0]
hy = hxyz[1]
hz = hxyz[2]
x = hx*np.r_[0:i2+1] - hx/2
y = hy*np.r_[0:j2+1] - hy/2
z = hz*np.r_[0:k2+1] - hz/2
x, y, z = np.ix_(x, y, z)
r = np.sqrt(x*x + y*y + z*z)
if ne_flag:
IG = ne.evaluate("(-x*x*0.5*arctan(y*z/(x*r)) + y*z*log(x+r) - y*y*0.5*arctan(z*x/(y*r)) + z*x*log(y+r) - z*z*0.5*arctan(x*y/(z*r)) + x*y*log(z+r))")
else:
IG = (-x*x*0.5*np.arctan(y*z/(x*r)) + y*z*np.log(x+r)
-y*y*0.5*np.arctan(z*x/(y*r)) + z*x*np.log(y+r)
-z*z*0.5*np.arctan(x*y/(z*r)) + x*y*np.log(z+r))
kern = (IG[1:i2+1, 1:j2+1, 1:k2+1] - IG[0:i2, 1:j2+1, 1:k2+1]
-IG[1:i2+1, 0:j2, 1:k2+1] + IG[0:i2, 0:j2, 1:k2+1]
-IG[1:i2+1, 1:j2+1, 0:k2] + IG[0:i2, 1:j2+1, 0:k2]
+IG[1:i2+1, 0:j2, 0:k2] - IG[0:i2, 0:j2, 0:k2])
return kern
示例8: numexpr_apply
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def numexpr_apply(self, X, R, T):
x, px, y, py, tau, dp = np.copy((X[0], X[1], X[2], X[3], X[4], X[5]))
R00, R01, R02, R03, R04, R05 = R[0, 0], R[0, 1], R[0, 2], R[0, 3], R[0, 4], R[0, 5]
R10, R11, R12, R13, R14, R15 = R[1, 0], R[1, 1], R[1, 2], R[1, 3], R[1, 4], R[1, 5]
R20, R21, R22, R23, R24, R25 = R[2, 0], R[2, 1], R[2, 2], R[2, 3], R[2, 4], R[2, 5]
R30, R31, R32, R33, R34, R35 = R[3, 0], R[3, 1], R[3, 2], R[3, 3], R[3, 4], R[3, 5]
R40, R41, R42, R43, R44, R45 = R[4, 0], R[4, 1], R[4, 2], R[4, 3], R[4, 4], R[4, 5]
R50, R51, R52, R53, R54, R55 = R[5, 0], R[5, 1], R[5, 2], R[5, 3], R[5, 4], R[5, 5]
T000, T001, T005, T011, T015, T055, T022, T023, T033 = T[0, 0, 0], T[0, 0, 1], T[0, 0, 5], T[0, 1, 1], T[0, 1, 5], T[0, 5, 5], T[0, 2, 2],T[0, 2, 3], T[0, 3, 3]
T100, T101, T105, T111, T115, T155, T122, T123, T133 = T[1, 0, 0], T[1, 0, 1], T[1, 0, 5], T[1, 1, 1], T[1, 1, 5], T[1, 5, 5], T[1, 2, 2],T[1, 2, 3], T[1, 3, 3]
T202, T203, T212, T213, T225, T235 = T[2, 0, 2], T[2, 0, 3], T[2, 1, 2], T[2, 1, 3], T[2, 2, 5], T[2, 3, 5]
T302, T303, T312, T313, T325, T335 = T[3, 0, 2], T[3, 0, 3], T[3, 1, 2], T[3, 1, 3], T[3, 2, 5], T[3, 3, 5]
T400, T401, T405, T411, T415, T455, T422, T423, T433 = T[4, 0, 0], T[4, 0, 1], T[4, 0, 5], T[4, 1, 1], T[4, 1, 5], T[4, 5, 5], T[4, 2, 2], T[4, 2, 3], T[4, 3, 3]
X[0] = ne.evaluate('R00 * x + R01 * px + R02 * y + R03 * py + R04 * tau + R05 * dp + T000 * x*x + T001 * x*px + T005 * x*dp + T011 * px*px + T015 * px*dp + T055 * dp*dp + T022 * y*y + T023 * y*py + T033 * py*py')
X[1] = ne.evaluate('R10 * x + R11 * px + R12 * y + R13 * py + R14 * tau + R15 * dp + T100 * x*x + T101 * x*px + T105 * x*dp + T111 * px*px + T115 * px*dp + T155 * dp*dp + T122 * y*y + T123 * y*py + T133 * py*py')
X[2] = ne.evaluate('R20 * x + R21 * px + R22 * y + R23 * py + R24 * tau + R25 * dp + T202 * x*y + T203 * x*py + T212 * y*px + T213 * px*py + T225 * y*dp + T235 * py*dp')
X[3] = ne.evaluate('R30 * x + R31 * px + R32 * y + R33 * py + R34 * tau + R35 * dp + T302 * x*y + T303 * x*py + T312 * y*px + T313 * px*py + T325 * y*dp + T335 * py*dp')
X[4] = ne.evaluate('R40 * x + R41 * px + R42 * y + R43 * py + R44 * tau + R45 * dp + T400 * x*x + T401 * x*px + T405 * x*dp + T411 * px*px + T415 * px*dp + T455 * dp*dp + T422 * y*y + T423 * y*py + T433 * py*py') # + U5666*dp2*dp # third order
示例9: evaluate
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def evaluate(self):
"""Run the engine on the expression
This method performs alignment which is necessary no matter what engine
is being used, thus its implementation is in the base class.
Returns
-------
obj : object
The result of the passed expression.
"""
if not self._is_aligned:
self.result_type, self.aligned_axes = _align(self.expr.terms)
# make sure no names in resolvers and locals/globals clash
self.pre_evaluate()
res = self._evaluate()
return _reconstruct_object(self.result_type, res, self.aligned_axes,
self.expr.terms.return_type)
示例10: _evaluate
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def _evaluate(self):
import numexpr as ne
# add the resolvers to locals
self.expr.add_resolvers_to_locals()
# convert the expression to a valid numexpr expression
s = self.convert()
try:
return ne.evaluate(s, local_dict=self.expr.env.locals,
global_dict=self.expr.env.globals,
truediv=self.expr.truediv)
except KeyError as e:
# python 3 compat kludge
try:
msg = e.message
except AttributeError:
msg = compat.text_type(e)
raise UndefinedVariableError(msg)
示例11: evaluate
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def evaluate(op, op_str, a, b, raise_on_error=False, use_numexpr=True,
**eval_kwargs):
""" evaluate and return the expression of the op on a and b
Parameters
----------
op : the actual operand
op_str: the string version of the op
a : left operand
b : right operand
raise_on_error : pass the error to the higher level if indicated
(default is False), otherwise evaluate the op with and
return the results
use_numexpr : whether to try to use numexpr (default True)
"""
if use_numexpr:
return _evaluate(op, op_str, a, b, raise_on_error=raise_on_error,
**eval_kwargs)
return _evaluate_standard(op, op_str, a, b, raise_on_error=raise_on_error)
示例12: where
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def where(cond, a, b, raise_on_error=False, use_numexpr=True):
""" evaluate the where condition cond on a and b
Parameters
----------
cond : a boolean array
a : return if cond is True
b : return if cond is False
raise_on_error : pass the error to the higher level if indicated
(default is False), otherwise evaluate the op with and
return the results
use_numexpr : whether to try to use numexpr (default True)
"""
if use_numexpr:
return _where(cond, a, b, raise_on_error=raise_on_error)
return _where_standard(cond, a, b, raise_on_error=raise_on_error)
示例13: dominant_screen_color
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def dominant_screen_color(initial_color, func_bounds=lambda: None):
"""
https://stackoverflow.com/questions/50899692/most-dominant-color-in-rgb-image-opencv-numpy-python
"""
monitor = get_monitor_bounds(func_bounds)
if "full" in monitor:
screenshot = getScreenAsImage()
else:
screenshot = getRectAsImage(str2list(monitor, int))
downscale_width, downscale_height = screenshot.width // 4, screenshot.height // 4
screenshot = screenshot.resize((downscale_width, downscale_height), Image.HAMMING)
a = np.array(screenshot)
a2D = a.reshape(-1, a.shape[-1])
col_range = (256, 256, 256) # generically : a2D.max(0)+1
eval_params = {'a0': a2D[:, 0], 'a1': a2D[:, 1], 'a2': a2D[:, 2],
's0': col_range[0], 's1': col_range[1]}
a1D = ne.evaluate('a0*s0*s1+a1*s0+a2', eval_params)
color = np.unravel_index(np.bincount(a1D).argmax(), col_range)
color_hsbk = list(utils.RGBtoHSBK(color, temperature=initial_color[3]))
# color_hsbk[2] = initial_color[2] # TODO Decide this
return color_hsbk
示例14: normalize_mi_ma
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def normalize_mi_ma(x, mi, ma, clip=False, eps=1e-20, dtype=np.float32):
if dtype is not None:
x = x.astype(dtype,copy=False)
mi = dtype(mi) if np.isscalar(mi) else mi.astype(dtype,copy=False)
ma = dtype(ma) if np.isscalar(ma) else ma.astype(dtype,copy=False)
eps = dtype(eps)
try:
import numexpr
x = numexpr.evaluate("(x - mi) / ( ma - mi + eps )")
except ImportError:
x = (x - mi) / ( ma - mi + eps )
if clip:
x = np.clip(x,0,1)
return x
示例15: _compute
# 需要导入模块: import numexpr [as 别名]
# 或者: from numexpr import evaluate [as 别名]
def _compute(self, arrays, dates, assets, mask):
"""
Compute our stored expression string with numexpr.
"""
out = full(mask.shape, self.missing_value, dtype=self.dtype)
# This writes directly into our output buffer.
numexpr.evaluate(
self._expr,
local_dict={
"x_%d" % idx: array
for idx, array in enumerate(arrays)
},
global_dict={'inf': inf},
out=out,
)
return out