本文整理匯總了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)