Python numpy.heaviside() Examples
The following are 8
code examples of numpy.heaviside().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: math_ops.py From trax with Apache License 2.0 | 5 votes |
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
Example #2
Source File: forecast_models.py From anticipy with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #3
Source File: forecast_models.py From anticipy with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #4
Source File: IVD_dummy.py From qkit with GNU General Public License v2.0 | 5 votes |
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)
Example #5
Source File: feature_functions.py From seglearn with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #6
Source File: helpers.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #7
Source File: test_quantity_ufuncs.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #8
Source File: test_quantity_ufuncs.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)