Python numpy.bitwise_not() Examples
The following are 30
code examples of numpy.bitwise_not().
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: lax_numpy_test.py From trax with Apache License 2.0 | 6 votes |
def testBitwiseOp(self, onp_op, lnp_op, rng_factory, shapes, dtypes): rng = rng_factory() args_maker = self._GetArgsMaker(rng, shapes, dtypes) has_python_scalar = jtu.PYTHON_SCALAR_SHAPE in shapes self._CheckAgainstNumpy(onp_op, lnp_op, args_maker, check_dtypes=True) if onp_op == onp.bitwise_not and has_python_scalar: # For bitwise_not with a Python `int`, npe.jit may choose a different # dtype for the `int` from onp's choice, which may result in a different # result value, so we skip _CompileAndCheck. return # Numpy does value-dependent dtype promotion on Python/numpy/array scalars # which `jit` can't do (when np.result_type is called inside `jit`, tensor # values are not available), so we skip dtype check in this case. check_dtypes = not(set(shapes) & set([jtu.NUMPY_SCALAR_SHAPE, jtu.PYTHON_SCALAR_SHAPE, ()])) self._CompileAndCheck(lnp_op, args_maker, check_dtypes=check_dtypes)
Example #2
Source File: test_umath.py From pySINDy with MIT License | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #3
Source File: minmax.py From histogrammar-python with Apache License 2.0 | 6 votes |
def _numpy(self, data, weights, shape): q = self.quantity(data) self._checkNPQuantity(q, shape) self._checkNPWeights(weights, shape) weights = self._makeNPWeights(weights, shape) # no possibility of exception from here on out (for rollback) import numpy selection = numpy.isnan(q) numpy.bitwise_not(selection, selection) numpy.bitwise_and(selection, weights > 0.0, selection) q = q[selection] self.entries += float(weights.sum()) if math.isnan(self.min): if q.shape[0] > 0: self.min = float(q.min()) else: if q.shape[0] > 0: self.min = min(self.min, float(q.min()))
Example #4
Source File: test_umath.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #5
Source File: test_umath.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #6
Source File: test_umath.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #7
Source File: test_umath.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #8
Source File: sum.py From histogrammar-python with Apache License 2.0 | 6 votes |
def _numpy(self, data, weights, shape): q = self.quantity(data) self._checkNPQuantity(q, shape) self._checkNPWeights(weights, shape) weights = self._makeNPWeights(weights, shape) # no possibility of exception from here on out (for rollback) self.entries += float(weights.sum()) import numpy selection = numpy.isnan(q) numpy.bitwise_not(selection, selection) numpy.bitwise_and(selection, weights > 0.0, selection) q = q[selection] weights = weights[selection] q *= weights self.sum += float(q.sum())
Example #9
Source File: test_umath.py From coffeegrindsize with MIT License | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #10
Source File: ArmaJump.py From Conditional_Density_Estimation with MIT License | 6 votes |
def simulate_conditional(self, X): """ Draws random samples from the conditional distribution Args: X: x to be conditioned on when drawing a sample from y ~ p(y|x) - numpy array of shape (n_samples, ndim_x) Returns: Conditional random samples y drawn from p(y|x) - numpy array of shape (n_samples, ndim_y) """ mean = self.arma_c * (1 - self.arma_a1) + self.arma_a1 * X y_ar = self.random_state.normal(loc=mean, scale=self.std, size=X.shape[0]) mean_jump = mean + self.jump_mean y_jump = self.random_state.normal(loc=mean_jump, scale=self.jump_std, size=X.shape[0]) jump_bernoulli = self.random_state.uniform(size=X.shape[0]) < self.jump_prob return X, np.select([jump_bernoulli, np.bitwise_not(jump_bernoulli)], [y_jump, y_ar])
Example #11
Source File: test_umath.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #12
Source File: test_umath.py From vnpy_crypto with MIT License | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #13
Source File: test_umath.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #14
Source File: test_umath.py From recruit with Apache License 2.0 | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #15
Source File: test_umath.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #16
Source File: test_simple.py From starfish with MIT License | 5 votes |
def test_success(): mask_collection_0 = binary_mask_collection_2d() binary_arrays, physical_ticks = binary_arrays_2d() binary_arrays_negated = [ np.bitwise_not(binary_array) for binary_array in binary_arrays ] mask_collection_1 = BinaryMaskCollection.from_binary_arrays_and_ticks( binary_arrays_negated, None, physical_ticks, None) merged = SimpleMerge().run([mask_collection_0, mask_collection_1]) assert _ticks_equal(merged._pixel_ticks, mask_collection_0._pixel_ticks) assert _ticks_equal(merged._physical_ticks, mask_collection_0._physical_ticks) assert len(mask_collection_0) + len(mask_collection_1) == len(merged) # go through all the original uncroppped masks, and verify that they are somewhere in the merged # set. for mask_collection in (mask_collection_0, mask_collection_1): for ix in range(len(mask_collection)): uncropped_original_mask = mask_collection.uncropped_mask(ix) for jx in range(len(merged)): uncropped_copy_mask = merged.uncropped_mask(jx) if uncropped_original_mask.equals(uncropped_copy_mask): # found the copy, break break else: pytest.fail("could not find mask in merged set.")
Example #17
Source File: test_simple.py From starfish with MIT License | 5 votes |
def test_physical_tick_mismatch(): mask_collection_0 = binary_mask_collection_2d() mask_collection_0._physical_ticks[Coordinates.X] = np.asarray( mask_collection_0._physical_ticks[Coordinates.X]) + 1 binary_arrays, physical_ticks = binary_arrays_2d() binary_arrays_negated = [ np.bitwise_not(binary_array) for binary_array in binary_arrays ] mask_collection_1 = BinaryMaskCollection.from_binary_arrays_and_ticks( binary_arrays_negated, None, physical_ticks, None) with pytest.raises(ValueError): SimpleMerge().run([mask_collection_0, mask_collection_1])
Example #18
Source File: test_simple.py From starfish with MIT License | 5 votes |
def test_pixel_tick_mismatch(): mask_collection_0 = binary_mask_collection_2d() mask_collection_0._pixel_ticks[Axes.X.value] = np.asarray( mask_collection_0._pixel_ticks[Axes.X.value]) + 1 binary_arrays, physical_ticks = binary_arrays_2d() binary_arrays_negated = [ np.bitwise_not(binary_array) for binary_array in binary_arrays ] mask_collection_1 = BinaryMaskCollection.from_binary_arrays_and_ticks( binary_arrays_negated, None, physical_ticks, None) with pytest.raises(ValueError): SimpleMerge().run([mask_collection_0, mask_collection_1])
Example #19
Source File: stack.py From histogrammar-python with Apache License 2.0 | 5 votes |
def _numpy(self, data, weights, shape): q = self.quantity(data) self._checkNPQuantity(q, shape) self._checkNPWeights(weights, shape) weights = self._makeNPWeights(weights, shape) newentries = weights.sum() import numpy selection = numpy.isnan(q) numpy.bitwise_not(selection, selection) subweights = weights.copy() subweights[selection] = 0.0 self.nanflow._numpy(data, subweights, shape) # avoid nan warning in calculations by flinging the nans elsewhere numpy.bitwise_not(selection, selection) q = numpy.array(q, dtype=numpy.float64) q[selection] = float("-inf") weights = weights.copy() weights[selection] = 0.0 selection = numpy.empty(q.shape, dtype=numpy.bool) for threshold, sub in self.bins: numpy.less(q, threshold, selection) subweights[:] = weights subweights[selection] = 0.0 sub._numpy(data, subweights, shape) # no possibility of exception from here on out (for rollback) self.entries += float(newentries)
Example #20
Source File: transform.py From RLTrader with GNU General Public License v3.0 | 5 votes |
def transform(iterable: Iterable, inplace: bool = True, columns: List[str] = None, transform_fn: Callable[[Iterable], Iterable] = None): if inplace is True: transformed_iterable = iterable else: transformed_iterable = iterable.copy() if isinstance(transformed_iterable, pd.DataFrame): is_list = False else: is_list = True transformed_iterable = pd.DataFrame(transformed_iterable, columns=columns) transformed_iterable.fillna(0, inplace=True) if transform_fn is None: raise NotImplementedError() if columns is None: columns = transformed_iterable.columns for column in columns: transformed_iterable[column] = transform_fn(transformed_iterable[column]) transformed_iterable.fillna(method="bfill", inplace=True) transformed_iterable[np.bitwise_not(np.isfinite(transformed_iterable))] = 0 if is_list: transformed_iterable = transformed_iterable.values return transformed_iterable
Example #21
Source File: irregularlybin.py From histogrammar-python with Apache License 2.0 | 5 votes |
def _numpy(self, data, weights, shape): q = self.quantity(data) self._checkNPQuantity(q, shape) self._checkNPWeights(weights, shape) weights = self._makeNPWeights(weights, shape) newentries = weights.sum() import numpy selection = numpy.isnan(q) numpy.bitwise_not(selection, selection) subweights = weights.copy() subweights[selection] = 0.0 self.nanflow._numpy(data, subweights, shape) # avoid nan warning in calculations by flinging the nans elsewhere numpy.bitwise_not(selection, selection) q = numpy.array(q, dtype=numpy.float64) q[selection] = float("-inf") weights = weights.copy() weights[selection] = 0.0 # FIXME: the case of all Counts could be optimized with numpy.histogram (see CentrallyBin for an example) selection = numpy.empty(q.shape, dtype=numpy.bool) selection2 = numpy.empty(q.shape, dtype=numpy.bool) subweights = weights.copy() for (low, sub), (high, _) in zip(self.bins, self.bins[1:] + ((float("nan"), None),)): numpy.greater_equal(q, low, selection) numpy.greater_equal(q, high, selection2) numpy.bitwise_not(selection2, selection2) numpy.bitwise_and(selection, selection2, selection) numpy.bitwise_not(selection, selection) subweights[:] = weights subweights[selection] = 0.0 sub._numpy(data, subweights, shape) # no possibility of exception from here on out (for rollback) self.entries += float(newentries)
Example #22
Source File: _numpy_bitstrings.py From xcs with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __invert__(self): """Overloads unary ~""" bits = numpy.bitwise_not(self._bits) # Make sure the bit array isn't writable so it can be used by the # constructor bits.flags.writeable = False return type(self)(bits)
Example #23
Source File: test_umath.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_types(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_(np.bitwise_not(zeros).dtype == dt, msg) assert_(np.bitwise_or(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_xor(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_and(zeros, zeros).dtype == dt, msg)
Example #24
Source File: test_umath.py From coffeegrindsize with MIT License | 5 votes |
def test_types(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_(np.bitwise_not(zeros).dtype == dt, msg) assert_(np.bitwise_or(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_xor(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_and(zeros, zeros).dtype == dt, msg)
Example #25
Source File: test_topi_broadcast.py From incubator-tvm with Apache License 2.0 | 5 votes |
def test_bitwise_not(): def test_apply( func, name, f_numpy, shape, dtype="int32", ): # Build the logic and compile the function A = te.placeholder(shape=shape, name="A", dtype=dtype) B = func(A) if isinstance(A, tvm.tir.PrimExpr): assert (isinstance(B, tvm.tir.PrimExpr)) return def check_device(device): ctx = tvm.context(device, 0) if not ctx.exist: print("Skip because %s is not enabled" % device) return print("Running on target: %s" % device) with tvm.target.create(device): s = topi.testing.get_broadcast_schedule(device)(B) foo = tvm.build(s, [A, B], device, name=name) data_npy = np.random.uniform(size=shape).astype(A.dtype) data_nd = tvm.nd.array(data_npy, ctx) out_npy = f_numpy(data_npy) out_nd = tvm.nd.array(np.empty(data_npy.shape).astype(B.dtype), ctx) foo(data_nd, out_nd) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy) for device in get_all_backend(): check_device(device) test_apply(topi.bitwise_not, "bitwise_not", np.bitwise_not, ()) test_apply(topi.bitwise_not, "bitwise_not", np.bitwise_not, (2, 1, 2))
Example #26
Source File: test_umath.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def test_types(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_(np.bitwise_not(zeros).dtype == dt, msg) assert_(np.bitwise_or(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_xor(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_and(zeros, zeros).dtype == dt, msg)
Example #27
Source File: test_umath.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_types(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_(np.bitwise_not(zeros).dtype == dt, msg) assert_(np.bitwise_or(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_xor(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_and(zeros, zeros).dtype == dt, msg)
Example #28
Source File: MIMAS.py From Aegean with Academic Free License v3.0 | 5 votes |
def mask_table(region, table, negate=False, racol='ra', deccol='dec'): """ Apply a given mask (region) to the table, removing all the rows with ra/dec inside the region If negate=False then remove the rows with ra/dec outside the region. Parameters ---------- region : :class:`AegeanTools.regions.Region` Region to mask. table : Astropy.table.Table Table to be masked. negate : bool If True then pixels *outside* the region are masked. Default = False. racol, deccol : str The name of the columns in `table` that should be interpreted as ra and dec. Default = 'ra', 'dec' Returns ------- masked : Astropy.table.Table A view of the given table which has been masked. """ inside = region.sky_within(table[racol], table[deccol], degin=True) if not negate: mask = np.bitwise_not(inside) else: mask = inside return table[mask]
Example #29
Source File: TradingEnv.py From RLTrader with GNU General Public License v3.0 | 5 votes |
def _next_observation(self): self.current_ohlcv = self.data_provider.next_ohlcv() self.timestamps.append(pd.to_datetime(self.current_ohlcv.Date.item(), unit='s')) self.observations = self.observations.append(self.current_ohlcv, ignore_index=True) if self.stationarize_obs: observations = log_and_difference(self.observations, inplace=False) else: observations = self.observations if self.normalize_obs: observations = max_min_normalize(observations) obs = observations.values[-1] if self.stationarize_obs: scaled_history = log_and_difference(self.account_history, inplace=False) else: scaled_history = self.account_history if self.normalize_obs: scaled_history = max_min_normalize(scaled_history, inplace=False) obs = np.insert(obs, len(obs), scaled_history.values[-1], axis=0) obs = np.reshape(obs.astype('float16'), self.obs_shape) obs[np.bitwise_not(np.isfinite(obs))] = 0 return obs
Example #30
Source File: test_umath.py From recruit with Apache License 2.0 | 5 votes |
def test_types(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_(np.bitwise_not(zeros).dtype == dt, msg) assert_(np.bitwise_or(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_xor(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_and(zeros, zeros).dtype == dt, msg)