本文整理汇总了Python中numpy.greater方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.greater方法的具体用法?Python numpy.greater怎么用?Python numpy.greater使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.greater方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
def __init__(self, monitor='val_loss',
min_delta=1e-6, patience=5,mode='min'):
#{{{
super(EarlyStopping, self).__init__()
self.monitor = monitor
self.patience = patience
self.min_delta = min_delta
self.wait = 0
self.stopped_epoch = 0
self.stop_training=False;
if mode =="min":
self.monitor_op = np.less;
elif mode == "max":
self.monitor_op = np.greater;
else:
assert 0,"unknown early stop mode:";
self.min_delta *= -1
#}}}
示例2: test_greater
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
def test_greater():
"""Test for logical greater in onnx operators."""
input1 = np.random.rand(1, 3, 4, 5).astype("float32")
input2 = np.random.rand(1, 5).astype("float32")
inputs = [helper.make_tensor_value_info("input1", TensorProto.FLOAT, shape=(1, 3, 4, 5)),
helper.make_tensor_value_info("input2", TensorProto.FLOAT, shape=(1, 5))]
outputs = [helper.make_tensor_value_info("output", TensorProto.FLOAT, shape=(1, 3, 4, 5))]
nodes = [helper.make_node("Greater", ["input1", "input2"], ["output"])]
graph = helper.make_graph(nodes,
"greater_test",
inputs,
outputs)
greater_model = helper.make_model(graph)
bkd_rep = mxnet_backend.prepare(greater_model)
numpy_op = np.greater(input1, input2).astype(np.float32)
output = bkd_rep.run([input1, input2])
npt.assert_almost_equal(output[0], numpy_op)
示例3: test_lesser
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
def test_lesser():
"""Test for logical greater in onnx operators."""
input1 = np.random.rand(1, 3, 4, 5).astype("float32")
input2 = np.random.rand(1, 5).astype("float32")
inputs = [helper.make_tensor_value_info("input1", TensorProto.FLOAT, shape=(1, 3, 4, 5)),
helper.make_tensor_value_info("input2", TensorProto.FLOAT, shape=(1, 5))]
outputs = [helper.make_tensor_value_info("output", TensorProto.FLOAT, shape=(1, 3, 4, 5))]
nodes = [helper.make_node("Less", ["input1", "input2"], ["output"])]
graph = helper.make_graph(nodes,
"lesser_test",
inputs,
outputs)
greater_model = helper.make_model(graph)
bkd_rep = mxnet_backend.prepare(greater_model)
numpy_op = np.less(input1, input2).astype(np.float32)
output = bkd_rep.run([input1, input2])
npt.assert_almost_equal(output[0], numpy_op)
示例4: test_equal
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
def test_equal():
"""Test for logical greater in onnx operators."""
input1 = np.random.rand(1, 3, 4, 5).astype("float32")
input2 = np.random.rand(1, 5).astype("float32")
inputs = [helper.make_tensor_value_info("input1", TensorProto.FLOAT, shape=(1, 3, 4, 5)),
helper.make_tensor_value_info("input2", TensorProto.FLOAT, shape=(1, 5))]
outputs = [helper.make_tensor_value_info("output", TensorProto.FLOAT, shape=(1, 3, 4, 5))]
nodes = [helper.make_node("Equal", ["input1", "input2"], ["output"])]
graph = helper.make_graph(nodes,
"equal_test",
inputs,
outputs)
greater_model = helper.make_model(graph)
bkd_rep = mxnet_backend.prepare(greater_model)
numpy_op = np.equal(input1, input2).astype(np.float32)
output = bkd_rep.run([input1, input2])
npt.assert_almost_equal(output[0], numpy_op)
示例5: handle_rolling
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
def handle_rolling(agg, granularity, timestamps, values, is_aggregated,
references, window):
if window > len(values):
raise exceptions.UnAggregableTimeseries(
references,
"Rolling window '%d' is greater than serie length '%d'" %
(window, len(values))
)
timestamps = timestamps[window - 1:]
values = values.T
# rigtorp.se/2011/01/01/rolling-statistics-numpy.html
shape = values.shape[:-1] + (values.shape[-1] - window + 1, window)
strides = values.strides + (values.strides[-1],)
new_values = AGG_MAP[agg](as_strided(values, shape=shape, strides=strides),
axis=-1)
if agg.startswith("rate:"):
timestamps = timestamps[1:]
return granularity, timestamps, new_values.T, is_aggregated
示例6: test_datetime_compare_nat
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
def test_datetime_compare_nat(self):
dt_nat = np.datetime64('NaT', 'D')
dt_other = np.datetime64('2000-01-01')
td_nat = np.timedelta64('NaT', 'h')
td_other = np.timedelta64(1, 'h')
for op in [np.equal, np.less, np.less_equal,
np.greater, np.greater_equal]:
assert_(not op(dt_nat, dt_nat))
assert_(not op(dt_nat, dt_other))
assert_(not op(dt_other, dt_nat))
assert_(not op(td_nat, td_nat))
assert_(not op(td_nat, td_other))
assert_(not op(td_other, td_nat))
assert_(np.not_equal(dt_nat, dt_nat))
assert_(np.not_equal(dt_nat, dt_other))
assert_(np.not_equal(dt_other, dt_nat))
assert_(np.not_equal(td_nat, td_nat))
assert_(np.not_equal(td_nat, td_other))
assert_(np.not_equal(td_other, td_nat))
示例7: test_NotImplemented_not_returned
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
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,
np.greater, np.greater_equal, np.less, np.less_equal,
np.equal, np.not_equal]
a = np.array('1')
b = 1
c = np.array([1., 2.])
for f in binary_funcs:
assert_raises(TypeError, f, a, b)
assert_raises(TypeError, f, c, a)
示例8: equal
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
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)
示例9: not_equal
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
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)
示例10: greater_equal
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
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)
示例11: less_equal
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
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)
示例12: greater
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
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)
示例13: argmax
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
def argmax(self, axis=None, out=None):
"""Return indices of maximum elements along an axis.
Implicit zero elements are also taken into account. If there are
several maximum values, the index of the first occurrence is returned.
Parameters
----------
axis : {-2, -1, 0, 1, None}, optional
Axis along which the argmax is computed. If None (default), index
of the maximum element in the flatten data is returned.
out : None, optional
This argument is in the signature *solely* for NumPy
compatibility reasons. Do not pass in anything except for
the default value, as this argument is not used.
Returns
-------
ind : np.matrix or int
Indices of maximum elements. If matrix, its size along `axis` is 1.
"""
return self._arg_min_or_max(axis, out, np.argmax, np.greater)
示例14: _reset
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
def _reset(self):
"""Resets wait counter and cooldown counter.
"""
if self.mode not in ['auto', 'min', 'max']:
warnings.warn('Learning Rate Plateau Reducing mode %s is unknown, '
'fallback to auto mode.' % (self.mode), RuntimeWarning)
self.mode = 'auto'
if (self.mode == 'min' or
(self.mode == 'auto' and 'acc' not in self.monitor)):
self.monitor_op = lambda a, b: np.less(a, b - self.epsilon)
self.best = np.Inf
else:
self.monitor_op = lambda a, b: np.greater(a, b + self.epsilon)
self.best = -np.Inf
self.cooldown_counter = 0
self.wait = 0
self.lr_epsilon = self.min_lr * 1e-4
示例15: test_minmax_func
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import greater [as 别名]
def test_minmax_func(self):
# Tests minimum and maximum.
(x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
# max doesn't work if shaped
xr = np.ravel(x)
xmr = ravel(xm)
# following are true because of careful selection of data
assert_equal(max(xr), maximum(xmr))
assert_equal(min(xr), minimum(xmr))
assert_equal(minimum([1, 2, 3], [4, 0, 9]), [1, 0, 3])
assert_equal(maximum([1, 2, 3], [4, 0, 9]), [4, 2, 9])
x = arange(5)
y = arange(5) - 2
x[3] = masked
y[0] = masked
assert_equal(minimum(x, y), where(less(x, y), x, y))
assert_equal(maximum(x, y), where(greater(x, y), x, y))
assert_(minimum(x) == 0)
assert_(maximum(x) == 4)
x = arange(4).reshape(2, 2)
x[-1, -1] = masked
assert_equal(maximum(x), 2)