Python numpy.heaviside() Examples

The following are 8 code examples for showing how to use numpy.heaviside(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module numpy , or try the search function .

Example 1
Project: trax   Author: google   File: math_ops.py    License: Apache License 2.0 5 votes vote down vote up
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
Project: anticipy   Author: sky-uk   File: forecast_models.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Project: anticipy   Author: sky-uk   File: forecast_models.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Project: qkit   Author: qkitgroup   File: IVD_dummy.py    License: GNU General Public License v2.0 5 votes vote down vote up
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
Project: seglearn   Author: dmbee   File: feature_functions.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Project: Carnets   Author: holzschu   File: helpers.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Project: Carnets   Author: holzschu   File: test_quantity_ufuncs.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Project: Carnets   Author: holzschu   File: test_quantity_ufuncs.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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)