本文整理汇总了Python中numpy.heaviside方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.heaviside方法的具体用法?Python numpy.heaviside怎么用?Python numpy.heaviside使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.heaviside方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: heaviside
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import heaviside [as 别名]
def heaviside(x1, x2):
def f(x1, x2):
return tf.where(x1 < 0, tf.constant(0, dtype=x2.dtype),
tf.where(x1 > 0, tf.constant(1, dtype=x2.dtype), x2))
y = _bin_op(f, x1, x2)
if not np.issubdtype(y.dtype, np.inexact):
y = y.astype(dtypes.default_float_type())
return y
示例2: _f_step
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import heaviside [as 别名]
def _f_step(a_x, a_date, params, is_mult=False, **kwargs):
(A, B) = params
if is_mult:
y = 1 + (B - 1) * np.heaviside(a_x - A, 1)
else:
y = B * np.heaviside(a_x - A, 1)
return y
# TODO: Implement initialisation for multiplicative composition
示例3: _f_ramp
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import heaviside [as 别名]
def _f_ramp(a_x, a_date, params, is_mult=False, **kwargs):
(A, B) = params
if is_mult:
y = 1 + (a_x - A) * (B) * np.heaviside(a_x - A, 1)
else:
y = (a_x - A) * B * np.heaviside(a_x - A, 1)
return y
示例4: get_IVC_JJ
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import heaviside [as 别名]
def get_IVC_JJ(x, Ic, Rn, SNR):
sign = np.sign(x[-1] - x[0])
return Rn * x * np.heaviside(np.abs(x) - Ic, int(sign > 0)) \
+ (np.heaviside(x, int(sign > 0)) - np.heaviside(x + sign * Ic, 0)) * Ic * Rn \
+ Ic * Rn / SNR * np.random.rand(x.size)
示例5: __call__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import heaviside [as 别名]
def __call__(self, X):
sign = np.heaviside(-1 * X[:, :-1] * X[:, 1:], 0)
abs_diff = np.abs(np.diff(X, axis=1))
return np.sum(sign * abs_diff >= self.threshold, axis=1, dtype=X.dtype)
示例6: helper_heaviside
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import heaviside [as 别名]
def helper_heaviside(f, unit1, unit2):
try:
converter2 = (get_converter(unit2, dimensionless_unscaled)
if unit2 is not None else None)
except UnitsError:
raise UnitTypeError("Can only apply 'heaviside' function with a "
"dimensionless second argument.")
return ([None, converter2], dimensionless_unscaled)
示例7: test_heaviside_scalar
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import heaviside [as 别名]
def test_heaviside_scalar(self):
assert np.heaviside(0. * u.m, 0.5) == 0.5 * u.dimensionless_unscaled
assert np.heaviside(0. * u.s,
25 * u.percent) == 0.25 * u.dimensionless_unscaled
assert np.heaviside(2. * u.J, 0.25) == 1. * u.dimensionless_unscaled
示例8: test_heaviside_array
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import heaviside [as 别名]
def test_heaviside_array(self):
values = np.array([-1., 0., 0., +1.])
halfway = np.array([0.75, 0.25, 0.75, 0.25]) * u.dimensionless_unscaled
assert np.all(np.heaviside(values * u.m,
halfway * u.dimensionless_unscaled) ==
[0, 0.25, 0.75, +1.] * u.dimensionless_unscaled)