我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用numpy.not_equal()。
def test_mask_value(self): result = self.model.predict(self.data) np.testing.assert_array_almost_equal( result[:, 1:, :], np.zeros(( self.data_size, self.max_length - 1, self.encoding_size )) ) np.testing.assert_equal( np.any( np.not_equal( result[:, 0:1, self.cell_units:], np.zeros((self.data_size, 1, self.cell_units)) ) ), True )
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)
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)
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)
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)
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)
def test_truth_table_logical(self): # 2, 3 and 4 serves as true values input1 = [0, 0, 3, 2] input2 = [0, 4, 0, 2] typecodes = (np.typecodes['AllFloat'] + np.typecodes['AllInteger'] + '?') # boolean for dtype in map(np.dtype, typecodes): arg1 = np.asarray(input1, dtype=dtype) arg2 = np.asarray(input2, dtype=dtype) # OR out = [False, True, True, True] for func in (np.logical_or, np.maximum): assert_equal(func(arg1, arg2).astype(bool), out) # AND out = [False, False, False, True] for func in (np.logical_and, np.minimum): assert_equal(func(arg1, arg2).astype(bool), out) # XOR out = [False, True, True, False] for func in (np.logical_xor, np.not_equal): assert_equal(func(arg1, arg2).astype(bool), out)
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)
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)
def testCplxNotEqualGPU(self): shapes1 = [(5,4,3), (5,4), (1,), (5,)] shapes2 = [(5,4,3), (1,), (5,4), (5,)] for [sh0, sh1] in zip(shapes1, shapes2): x = (np.random.randn(np.prod(sh0)) + 1j*np.random.randn(np.prod(sh0))).astype(np.complex64) y = (np.random.randn(np.prod(sh1)) + 1j*np.random.randn(np.prod(sh1))).astype(np.complex64) if len(sh0) == 1: ix = np.random.permutation( np.arange(np.prod(sh1)))[:np.prod(sh1)//2] y[ix] = x[0] elif len(sh1) == 1: ix = np.random.permutation( np.arange(np.prod(sh0)))[:np.prod(sh0)//2] x[ix] = y[0] else: ix = np.random.permutation( np.arange(np.prod(sh0)))[:np.prod(sh0)//2] x[ix] = y[ix] x = np.reshape(x, sh0) y = np.reshape(y, sh1) self._compareGpu(x, y, np.not_equal, tf.not_equal)
def gen_hull(p, p_mask, f_encode, f_probi, options): # p: n_sizes * n_samples * data_dim n_sizes = p.shape[0] n_samples = p.shape[1] if p.ndim == 3 else 1 hprev = f_encode(p_mask, p) # n_sizes * n_samples * data_dim points = numpy.zeros((n_samples, n_sizes), dtype='int64') h = hprev[-1] c = numpy.zeros((n_samples, options['dim_proj']), dtype=config.floatX) xi = numpy.zeros((n_samples,), dtype='int64') xi_mask = numpy.ones((n_samples,), dtype=config.floatX) for i in range(n_sizes): h, c, probi = f_probi(p_mask[i], xi, h, c, hprev, p_mask, p) xi = probi.argmax(axis=0) xi *= xi_mask.astype(numpy.int64) # Avoid compatibility problem in numpy 1.10 xi_mask = (numpy.not_equal(xi, 0)).astype(config.floatX) if numpy.equal(xi_mask, 0).all(): break points[:, i] = xi return points