The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.
Example 1
def _constrained_sum_sample_pos(n, total): # in this setting, there will be no empty groups generated by this function n = int(n) total = int(total) normalized_list = [int(total) + 1] while sum(normalized_list) > total and np.greater_equal(normalized_list, np.zeros(n)).all(): indicator = True while indicator: normalized_list = list(map(round, map(lambda x: x * total, np.random.dirichlet(np.ones(n), 1).tolist()[0]))) normalized_list = list(map(int, normalized_list)) indicator = len(normalized_list) - np.count_nonzero(normalized_list) != 0 sum_ = 0 for ind, q in enumerate(normalized_list): if ind < len(normalized_list) - 1: sum_ += q # TODO: there is a bug here; sometimes it assigns -1 to the end of the array, but pass the while condition normalized_list[len(normalized_list) - 1] = abs(total - sum_) assert sum(normalized_list) == total, "ERROR: the constrainedSumSamplePos-sampled list does not sum to #edges." return map(str, normalized_list)
Example 2
def equal(x1, x2): """ Return (x1 == x2) element-wise. Unlike `numpy.equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- not_equal, greater_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '==', True)
Example 3
def not_equal(x1, x2): """ Return (x1 != x2) element-wise. Unlike `numpy.not_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, greater_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '!=', True)
Example 4
def greater_equal(x1, x2): """ Return (x1 >= x2) element-wise. Unlike `numpy.greater_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '>=', True)
Example 5
def less_equal(x1, x2): """ Return (x1 <= x2) element-wise. Unlike `numpy.less_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, greater, less """ return compare_chararrays(x1, x2, '<=', True)
Example 6
def greater(x1, x2): """ Return (x1 > x2) element-wise. Unlike `numpy.greater`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, less_equal, less """ return compare_chararrays(x1, x2, '>', True)
Example 7
def test_identity_equality_mismatch(self): a = np.array([np.nan], dtype=object) with warnings.catch_warnings(): warnings.filterwarnings('always', '', FutureWarning) assert_warns(FutureWarning, np.equal, a, a) assert_warns(FutureWarning, np.not_equal, a, a) with warnings.catch_warnings(): warnings.filterwarnings('error', '', FutureWarning) assert_raises(FutureWarning, np.equal, a, a) assert_raises(FutureWarning, np.not_equal, a, a) # And the other do not warn: with np.errstate(invalid='ignore'): np.less(a, a) np.greater(a, a) np.less_equal(a, a) np.greater_equal(a, a)
Example 8
def ntron_pulse(amplitude=1.0, rise_time=80e-12, hold_time=170e-12, fall_time=1.0e-9, sample_rate=12e9): delay = 2.0e-9 # Wait a few TCs for the rising edge duration = delay + hold_time + 6.0*fall_time # Wait 6 TCs for the slow decay pulse_points = int(duration*sample_rate) if pulse_points < 320: duration = 319/sample_rate # times = np.arange(0, duration, 1/sample_rate) times = np.linspace(0, duration, 320) else: pulse_points = 64*np.ceil(pulse_points/64.0) duration = (pulse_points-1)/sample_rate # times = np.arange(0, duration, 1/sample_rate) times = np.linspace(0, duration, pulse_points) rise_mask = np.less(times, delay) hold_mask = np.less(times, delay + hold_time)*np.greater_equal(times, delay) fall_mask = np.greater_equal(times, delay + hold_time) wf = rise_mask*np.exp((times-delay)/rise_time) wf += hold_mask wf += fall_mask*np.exp(-(times-delay-hold_time)/fall_time) return amplitude*wf
Example 9
def ntron_pulse(amplitude=1.0, rise_time=80e-12, hold_time=170e-12, fall_time=1.0e-9, sample_rate=12e9): delay = 2.0e-9 # Wait a few TCs for the rising edge duration = delay + hold_time + 6.0*fall_time # Wait 6 TCs for the slow decay pulse_points = int(duration*sample_rate) if pulse_points < 320: duration = 319/sample_rate # times = np.arange(0, duration, 1/sample_rate) times = np.linspace(0, duration, 320) else: pulse_points = 64*np.ceil(pulse_points/64.0) duration = (pulse_points-1)/sample_rate # times = np.arange(0, duration, 1/sample_rate) times = np.linspace(0, duration, pulse_points) rise_mask = np.less(times, delay) hold_mask = np.less(times, delay + hold_time)*np.greater_equal(times, delay) fall_mask = np.greater_equal(times, delay + hold_time) wf = rise_mask*np.exp((times-delay)/rise_time) wf += hold_mask wf += fall_mask*np.exp(-(times-delay-hold_time)/fall_time) return amplitude*wf
Example 10
def build(self, input_shape): super().build(input_shape) self.mask = np.ones(self.W_shape) assert mask.shape[0] == mask.shape[1] filter_size = self.mask.shape[0] filter_center = filter_size / 2 self.mask[math.ceil(filter_center):] = 0 self.mask[math.floor(filter_center):, math.ceil(filter_center):] = 0 if self.mono: if self.mask_type == 'A': self.mask[math.floor(filter_center), math.floor(filter_center)] = 0 else: op = np.greater_equal if self.mask_type == 'A' else np.greater for i in range(self.n_channels): for j in range(self.n_channels): if op(i, j): self.mask[math.floor(filter_center), math.floor(filter_center), i::self.n_channels, j::self.n_channels] = 0 self.mask = K.variable(self.mask)
Example 11
def points_in_front(self, points, inverted=False, ret_indices=False): ''' Given an array of points, return the points which lie either on the plane or in the half-space in front of it (i.e. in the direction of the plane normal). points: An array of points. inverted: When `True`, invert the logic. Return the points that lie behind the plane instead. ret_indices: When `True`, return the indices instead of the points themselves. ''' sign = self.sign(points) if inverted: mask = np.less_equal(sign, 0) else: mask = np.greater_equal(sign, 0) indices = np.flatnonzero(mask) return indices if ret_indices else points[indices]
Example 12
def equal(x1, x2): """ Return (x1 == x2) element-wise. Unlike `numpy.equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- not_equal, greater_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '==', True)
Example 13
def not_equal(x1, x2): """ Return (x1 != x2) element-wise. Unlike `numpy.not_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, greater_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '!=', True)
Example 14
def greater_equal(x1, x2): """ Return (x1 >= x2) element-wise. Unlike `numpy.greater_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '>=', True)
Example 15
def less_equal(x1, x2): """ Return (x1 <= x2) element-wise. Unlike `numpy.less_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, greater, less """ return compare_chararrays(x1, x2, '<=', True)
Example 16
def greater(x1, x2): """ Return (x1 > x2) element-wise. Unlike `numpy.greater`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, less_equal, less """ return compare_chararrays(x1, x2, '>', True)
Example 17
def test_identity_equality_mismatch(self): a = np.array([np.nan], dtype=object) with warnings.catch_warnings(): warnings.filterwarnings('always', '', FutureWarning) assert_warns(FutureWarning, np.equal, a, a) assert_warns(FutureWarning, np.not_equal, a, a) with warnings.catch_warnings(): warnings.filterwarnings('error', '', FutureWarning) assert_raises(FutureWarning, np.equal, a, a) assert_raises(FutureWarning, np.not_equal, a, a) # And the other do not warn: with np.errstate(invalid='ignore'): np.less(a, a) np.greater(a, a) np.less_equal(a, a) np.greater_equal(a, a)
Example 18
def equal(x1, x2): """ Return (x1 == x2) element-wise. Unlike `numpy.equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- not_equal, greater_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '==', True)
Example 19
def not_equal(x1, x2): """ Return (x1 != x2) element-wise. Unlike `numpy.not_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, greater_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '!=', True)
Example 20
def greater_equal(x1, x2): """ Return (x1 >= x2) element-wise. Unlike `numpy.greater_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '>=', True)
Example 21
def less_equal(x1, x2): """ Return (x1 <= x2) element-wise. Unlike `numpy.less_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, greater, less """ return compare_chararrays(x1, x2, '<=', True)
Example 22
def greater(x1, x2): """ Return (x1 > x2) element-wise. Unlike `numpy.greater`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, less_equal, less """ return compare_chararrays(x1, x2, '>', True)
Example 23
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example 24
def test_identity_equality_mismatch(self): a = np.array([np.nan], dtype=object) with warnings.catch_warnings(): warnings.filterwarnings('always', '', FutureWarning) assert_warns(FutureWarning, np.equal, a, a) assert_warns(FutureWarning, np.not_equal, a, a) with warnings.catch_warnings(): warnings.filterwarnings('error', '', FutureWarning) assert_raises(FutureWarning, np.equal, a, a) assert_raises(FutureWarning, np.not_equal, a, a) # And the other do not warn: with np.errstate(invalid='ignore'): np.less(a, a) np.greater(a, a) np.less_equal(a, a) np.greater_equal(a, a)
Example 25
def equal(x1, x2): """ Return (x1 == x2) element-wise. Unlike `numpy.equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- not_equal, greater_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '==', True)
Example 26
def greater_equal(x1, x2): """ Return (x1 >= x2) element-wise. Unlike `numpy.greater_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '>=', True)
Example 27
def less_equal(x1, x2): """ Return (x1 <= x2) element-wise. Unlike `numpy.less_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, greater, less """ return compare_chararrays(x1, x2, '<=', True)
Example 28
def greater(x1, x2): """ Return (x1 > x2) element-wise. Unlike `numpy.greater`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, less_equal, less """ return compare_chararrays(x1, x2, '>', True)
Example 29
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example 30
def test_identity_equality_mismatch(self): a = np.array([np.nan], dtype=object) with warnings.catch_warnings(): warnings.filterwarnings('always', '', FutureWarning) assert_warns(FutureWarning, np.equal, a, a) assert_warns(FutureWarning, np.not_equal, a, a) with warnings.catch_warnings(): warnings.filterwarnings('error', '', FutureWarning) assert_raises(FutureWarning, np.equal, a, a) assert_raises(FutureWarning, np.not_equal, a, a) # And the other do not warn: with np.errstate(invalid='ignore'): np.less(a, a) np.greater(a, a) np.less_equal(a, a) np.greater_equal(a, a)
Example 31
def equal(x1, x2): """ Return (x1 == x2) element-wise. Unlike `numpy.equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- not_equal, greater_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '==', True)
Example 32
def not_equal(x1, x2): """ Return (x1 != x2) element-wise. Unlike `numpy.not_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, greater_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '!=', True)
Example 33
def greater_equal(x1, x2): """ Return (x1 >= x2) element-wise. Unlike `numpy.greater_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '>=', True)
Example 34
def less_equal(x1, x2): """ Return (x1 <= x2) element-wise. Unlike `numpy.less_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, greater, less """ return compare_chararrays(x1, x2, '<=', True)
Example 35
def greater(x1, x2): """ Return (x1 > x2) element-wise. Unlike `numpy.greater`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, less_equal, less """ return compare_chararrays(x1, x2, '>', True)
Example 36
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example 37
def test_identity_equality_mismatch(self): a = np.array([np.nan], dtype=object) with warnings.catch_warnings(): warnings.filterwarnings('always', '', FutureWarning) assert_warns(FutureWarning, np.equal, a, a) assert_warns(FutureWarning, np.not_equal, a, a) with warnings.catch_warnings(): warnings.filterwarnings('error', '', FutureWarning) assert_raises(FutureWarning, np.equal, a, a) assert_raises(FutureWarning, np.not_equal, a, a) # And the other do not warn: with np.errstate(invalid='ignore'): np.less(a, a) np.greater(a, a) np.less_equal(a, a) np.greater_equal(a, a)
Example 38
def equal(x1, x2): """ Return (x1 == x2) element-wise. Unlike `numpy.equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- not_equal, greater_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '==', True)
Example 39
def not_equal(x1, x2): """ Return (x1 != x2) element-wise. Unlike `numpy.not_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, greater_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '!=', True)
Example 40
def greater_equal(x1, x2): """ Return (x1 >= x2) element-wise. Unlike `numpy.greater_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '>=', True)
Example 41
def less_equal(x1, x2): """ Return (x1 <= x2) element-wise. Unlike `numpy.less_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, greater, less """ return compare_chararrays(x1, x2, '<=', True)
Example 42
def greater(x1, x2): """ Return (x1 > x2) element-wise. Unlike `numpy.greater`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, less_equal, less """ return compare_chararrays(x1, x2, '>', True)
Example 43
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example 44
def test_identity_equality_mismatch(self): a = np.array([np.nan], dtype=object) with warnings.catch_warnings(): warnings.filterwarnings('always', '', FutureWarning) assert_warns(FutureWarning, np.equal, a, a) assert_warns(FutureWarning, np.not_equal, a, a) with warnings.catch_warnings(): warnings.filterwarnings('error', '', FutureWarning) assert_raises(FutureWarning, np.equal, a, a) assert_raises(FutureWarning, np.not_equal, a, a) # And the other do not warn: with np.errstate(invalid='ignore'): np.less(a, a) np.greater(a, a) np.less_equal(a, a) np.greater_equal(a, a)
Example 45
def amedian (inarray,numbins=1000): """ Calculates the COMPUTED median value of an array of numbers, given the number of bins to use for the histogram (more bins approaches finding the precise median value of the array; default number of bins = 1000). From G.W. Heiman's Basic Stats, or CRC Probability & Statistics. NOTE: THIS ROUTINE ALWAYS uses the entire passed array (flattens it first). Usage: amedian(inarray,numbins=1000) Returns: median calculated over ALL values in inarray """ inarray = N.ravel(inarray) (hist, smallest, binsize, extras) = ahistogram(inarray,numbins,[min(inarray),max(inarray)]) cumhist = N.cumsum(hist) # make cumulative histogram otherbins = N.greater_equal(cumhist,len(inarray)/2.0) otherbins = list(otherbins) # list of 0/1s, 1s start at median bin cfbin = otherbins.index(1) # get 1st(!) index holding 50%ile score LRL = smallest + binsize*cfbin # get lower read limit of that bin cfbelow = N.add.reduce(hist[0:cfbin]) # cum. freq. below bin freq = hist[cfbin] # frequency IN the 50%ile bin median = LRL + ((len(inarray)/2.0-cfbelow)/float(freq))*binsize # MEDIAN return median
Example 46
def atmin(a,lowerlimit=None,dimension=None,inclusive=1): """ Returns the minimum value of a, along dimension, including only values less than (or equal to, if inclusive=1) lowerlimit. If the limit is set to None, all values in the array are used. Usage: atmin(a,lowerlimit=None,dimension=None,inclusive=1) """ if inclusive: lowerfcn = N.greater else: lowerfcn = N.greater_equal if dimension == None: a = N.ravel(a) dimension = 0 if lowerlimit == None: lowerlimit = N.minimum.reduce(N.ravel(a))-11 biggest = N.maximum.reduce(N.ravel(a)) ta = N.where(lowerfcn(a,lowerlimit),a,biggest) return N.minimum.reduce(ta,dimension)
Example 47
def parse(cls, func): if isinstance(func, six.string_types): func = func.lower().strip() if func in [np.equal, '=', 'eq', '-eq', '==', 'is', 'equal', 'equal to']: return cls.eq elif func in [np.not_equal, '<>', 'ne', '-ne', '!=', 'not', 'not_equal', 'not equal to']: return cls.ne elif func in [np.greater, '>', 'gt', '-gt', 'above', 'after', 'greater', 'greater than']: return cls.gt elif func in [np.less, '<', 'lt', '-lt', 'below', 'before', 'less', 'less than']: return cls.lt elif func in [np.greater_equal, '>=', 'ge', '-ge', 'greater_equal', 'greater than or equal to']: return cls.ge elif func in [np.less_equal, '<=', 'le', '-le', 'less_equal', 'less than or equal to']: return cls.le raise ValueError('Invalid Comparison name: %s'%func) # ### Control Condition classes #
Example 48
def population_impacted(pop, arg1, operation=None, arg2=None): """ Compute population impacted using using comparison operators. For example, find the population impacted when demand < 90% expected. Parameters ----------- pop : pd.Series (index = node names) A pandas Series that contains population per node arg1 : pd.DataFrame (columns = node names) or pd.Series (index = node names) Argument 1 operation : numpy.ufunc Numpy universal comparison function, options = np.greater, np.greater_equal, np.less, np.less_equal, np.equal, np.not_equal arg2 : same size and type as arg1, or a scalar Argument 2 """ mask = query(arg1, operation, arg2) pop_impacted = mask.multiply(pop) return pop_impacted
Example 49
def prune_non_overlapping_boxes(boxlist1, boxlist2, minoverlap=0.0): """Prunes the boxes in boxlist1 that overlap less than thresh with boxlist2. For each box in boxlist1, we want its IOA to be more than minoverlap with at least one of the boxes in boxlist2. If it does not, we remove it. Args: boxlist1: BoxList holding N boxes. boxlist2: BoxList holding M boxes. minoverlap: Minimum required overlap between boxes, to count them as overlapping. Returns: A pruned boxlist with size [N', 4]. """ intersection_over_area = ioa(boxlist2, boxlist1) # [M, N] tensor intersection_over_area = np.amax(intersection_over_area, axis=0) # [N] tensor keep_bool = np.greater_equal(intersection_over_area, np.array(minoverlap)) keep_inds = np.nonzero(keep_bool)[0] new_boxlist1 = gather(boxlist1, keep_inds) return new_boxlist1
Example 50
def equal(x1, x2): """ Return (x1 == x2) element-wise. Unlike `numpy.equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- not_equal, greater_equal, less_equal, greater, less """ return compare_chararrays(x1, x2, '==', True)