Python numpy.bitwise_or() Examples
The following are 30 code examples for showing how to use numpy.bitwise_or(). 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: recruit Author: Frank-qlu File: test_ufunc.py License: Apache License 2.0 | 6 votes |
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)
Example 2
Project: recruit Author: Frank-qlu File: test_umath.py License: 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 3
Project: pytorch-semantic-segmentation Author: mapleneverfade File: label2Img.py License: MIT License | 6 votes |
def label_colormap(N=256): def bitget(byteval, idx): return ((byteval & (1 << idx)) != 0) cmap = np.zeros((N, 3)) for i in range(0, N): id = i r, g, b = 0, 0, 0 for j in range(0, 8): r = np.bitwise_or(r, (bitget(id, 0) << 7-j)) g = np.bitwise_or(g, (bitget(id, 1) << 7-j)) b = np.bitwise_or(b, (bitget(id, 2) << 7-j)) id = (id >> 3) cmap[i, 0] = r cmap[i, 1] = g cmap[i, 2] = b cmap = cmap.astype(np.float32) / 255 return cmap
Example 4
Project: Semantic-Segmentation-using-Adversarial-Networks Author: oyam File: utils.py License: MIT License | 6 votes |
def labelcolormap(N=256): cmap = np.zeros((N, 3)) for i in range(0, N): id = i r, g, b = 0, 0, 0 for j in range(0, 8): r = np.bitwise_or(r, (bitget(id, 0) << 7-j)) g = np.bitwise_or(g, (bitget(id, 1) << 7-j)) b = np.bitwise_or(b, (bitget(id, 2) << 7-j)) id = (id >> 3) cmap[i, 0] = r cmap[i, 1] = g cmap[i, 2] = b cmap = cmap.astype(np.float32) / 255 return cmap # ----------------------------------------------------------------------------- # Evaluation # -----------------------------------------------------------------------------
Example 5
Project: auto-alt-text-lambda-api Author: abhisuri97 File: test_ufunc.py License: MIT License | 6 votes |
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 6
Project: D-VAE Author: muhanzhang File: elemwise.py License: MIT License | 6 votes |
def set_ufunc(self, scalar_op): # This is probably a speed up of the implementation if isinstance(scalar_op, theano.scalar.basic.Add): self.ufunc = numpy.add elif isinstance(scalar_op, theano.scalar.basic.Mul): self.ufunc = numpy.multiply elif isinstance(scalar_op, theano.scalar.basic.Maximum): self.ufunc = numpy.maximum elif isinstance(scalar_op, theano.scalar.basic.Minimum): self.ufunc = numpy.minimum elif isinstance(scalar_op, theano.scalar.basic.AND): self.ufunc = numpy.bitwise_and elif isinstance(scalar_op, theano.scalar.basic.OR): self.ufunc = numpy.bitwise_or elif isinstance(scalar_op, theano.scalar.basic.XOR): self.ufunc = numpy.bitwise_xor else: self.ufunc = numpy.frompyfunc(scalar_op.impl, 2, 1)
Example 7
Project: vnpy_crypto Author: birforce File: test_ufunc.py License: MIT License | 6 votes |
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 8
Project: vnpy_crypto Author: birforce File: test_umath.py License: 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 9
Project: FCN_for_crack_recognition Author: OnionDoctor File: FCN_CrackAnalysis.py License: MIT License | 6 votes |
def Hilditch_skeleton(binary_image): size = binary_image.size skel = np.zeros(binary_image.shape, np.uint8) elem = np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]]) image = binary_image.copy() for _ in range(10000): eroded = ndi.binary_erosion(image, elem) temp = ndi.binary_dilation(eroded, elem) temp = image - temp skel = np.bitwise_or(skel, temp) image = eroded.copy() zeros = size - np.sum(image > 0) if zeros == size: break return skel
Example 10
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: test_ufunc.py License: MIT License | 6 votes |
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)
Example 11
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: test_umath.py License: 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
Project: labelKeypoint Author: Jeff-sjtu File: utils.py License: GNU General Public License v3.0 | 6 votes |
def label_colormap(N=256): def bitget(byteval, idx): return ((byteval & (1 << idx)) != 0) cmap = np.zeros((N, 3)) for i in range(0, N): id = i r, g, b = 0, 0, 0 for j in range(0, 8): r = np.bitwise_or(r, (bitget(id, 0) << 7-j)) g = np.bitwise_or(g, (bitget(id, 1) << 7-j)) b = np.bitwise_or(b, (bitget(id, 2) << 7-j)) id = (id >> 3) cmap[i, 0] = r cmap[i, 1] = g cmap[i, 2] = b cmap = cmap.astype(np.float32) / 255 return cmap
Example 13
Project: GraphicDesignPatternByPython Author: Relph1119 File: test_ufunc.py License: MIT License | 6 votes |
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 14
Project: GraphicDesignPatternByPython Author: Relph1119 File: test_umath.py License: 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 15
Project: attention-lvcsr Author: rizar File: elemwise.py License: MIT License | 6 votes |
def set_ufunc(self, scalar_op): # This is probably a speed up of the implementation if isinstance(scalar_op, theano.scalar.basic.Add): self.ufunc = numpy.add elif isinstance(scalar_op, theano.scalar.basic.Mul): self.ufunc = numpy.multiply elif isinstance(scalar_op, theano.scalar.basic.Maximum): self.ufunc = numpy.maximum elif isinstance(scalar_op, theano.scalar.basic.Minimum): self.ufunc = numpy.minimum elif isinstance(scalar_op, theano.scalar.basic.AND): self.ufunc = numpy.bitwise_and elif isinstance(scalar_op, theano.scalar.basic.OR): self.ufunc = numpy.bitwise_or elif isinstance(scalar_op, theano.scalar.basic.XOR): self.ufunc = numpy.bitwise_xor else: self.ufunc = numpy.frompyfunc(scalar_op.impl, 2, 1)
Example 16
Project: predictive-maintenance-using-machine-learning Author: awslabs File: test_ufunc.py License: Apache License 2.0 | 6 votes |
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)
Example 17
Project: predictive-maintenance-using-machine-learning Author: awslabs File: test_umath.py License: 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 18
Project: pySINDy Author: luckystarufo File: test_ufunc.py License: MIT License | 6 votes |
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 19
Project: pySINDy Author: luckystarufo File: test_umath.py License: 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 20
Project: deep-prior Author: moberweger File: importers.py License: GNU General Public License v3.0 | 6 votes |
def loadDepthMap(self,filename): """ Read a depth-map :param filename: file name to load :return: image data of depth image """ img = Image.open(filename) # top 8 bits of depth are packed into green channel and lower 8 bits into blue assert len(img.getbands()) == 3 r, g, b = img.split() r = np.asarray(r, np.int32) g = np.asarray(g, np.int32) b = np.asarray(b, np.int32) dpt = np.bitwise_or(np.left_shift(g, 8), b) imgdata = np.asarray(dpt, np.float32) return imgdata
Example 21
Project: mxnet-lambda Author: awslabs File: test_ufunc.py License: Apache License 2.0 | 6 votes |
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 22
Project: mxnet-lambda Author: awslabs File: test_umath.py License: 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 23
Project: dicom2nifti Author: icometrix File: common.py License: MIT License | 6 votes |
def _get_slice_pixeldata(dicom_slice): """ the slice and intercept calculation can cause the slices to have different dtypes we should get the correct dtype that can cover all of them :type dicom_slice: pydicom object :param dicom_slice: slice to get the pixeldata for """ data = dicom_slice.pixel_array # fix overflow issues for signed data where BitsStored is lower than BitsAllocated and PixelReprentation = 1 (signed) # for example a hitachi mri scan can have BitsAllocated 16 but BitsStored is 12 and HighBit 11 if dicom_slice.BitsAllocated != dicom_slice.BitsStored and \ dicom_slice.HighBit == dicom_slice.BitsStored - 1 and \ dicom_slice.PixelRepresentation == 1: if dicom_slice.BitsAllocated == 16: data = data.astype(numpy.int16) # assert that it is a signed type max_value = pow(2, dicom_slice.HighBit) - 1 invert_value = -1 ^ max_value data[data > max_value] = numpy.bitwise_or(data[data > max_value], invert_value) pass return apply_scaling(data, dicom_slice)
Example 24
Project: deep-prior-pp Author: moberweger File: importers.py License: GNU General Public License v3.0 | 6 votes |
def loadDepthMap(self, filename): """ Read a depth-map :param filename: file name to load :return: image data of depth image """ img = Image.open(filename) # top 8 bits of depth are packed into green channel and lower 8 bits into blue assert len(img.getbands()) == 3 r, g, b = img.split() r = np.asarray(r, np.int32) g = np.asarray(g, np.int32) b = np.asarray(b, np.int32) dpt = np.bitwise_or(np.left_shift(g, 8), b) imgdata = np.asarray(dpt, np.float32) return imgdata
Example 25
Project: cloud-volume Author: seung-lab File: py_compressed_segmentation.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def _pack_encoded_values(encoded_values, bits): # TODO optimize with np.packbits for bits == 1 if bits == 0: return bytes() else: values_per_32bit = 32 // bits assert np.all(encoded_values == encoded_values & ((1 << bits) - 1)) padded_values = np.empty( values_per_32bit * ceil_div(len(encoded_values), values_per_32bit), dtype="<I") padded_values[:len(encoded_values)] = encoded_values padded_values[len(encoded_values):] = 0 packed_values = functools.reduce( np.bitwise_or, (padded_values[shift::values_per_32bit] << (shift * bits) for shift in range(values_per_32bit))) return packed_values.tobytes()
Example 26
Project: music_led_strip_control Author: TobKra96 File: output.py License: MIT License | 6 votes |
def show(self, output_array): import _rpi_ws281x as ws # pylint: disable=import-error # Typecast the array to int output_array = output_array.clip(0, 255).astype(int) # sort the colors. grb g = np.left_shift(output_array[1][:].astype(int), 16) # pylint: disable=assignment-from-no-return r = np.left_shift(output_array[0][:].astype(int), 8) # pylint: disable=assignment-from-no-return b = output_array[2][:].astype(int) rgb = np.bitwise_or(np.bitwise_or(r, g), b).astype(int) # You can only use ws2811_leds_set with the custom version. #ws.ws2811_leds_set(self.channel, rgb) for i in range(self._led_count): ws.ws2811_led_set(self.channel, i, rgb[i].item()) resp = ws.ws2811_render(self._leds) if resp != ws.WS2811_SUCCESS: message = ws.ws2811_get_return_t_str(resp) raise RuntimeError('ws2811_render failed with code {0} ({1})'.format(resp, message))
Example 27
Project: Systematic-LEDs Author: not-matt File: devices.py License: MIT License | 6 votes |
def show(self, pixels): """Writes new LED values to the Raspberry Pi's LED strip Raspberry Pi uses the rpi_ws281x to control the LED strip directly. This function updates the LED strip with new values. """ # Truncate values and cast to integer n_pixels = pixels.shape[1] pixels = pixels.clip(0, 255).astype(int) # Optional gamma correction pixels = _GAMMA_TABLE[pixels] # Encode 24-bit LED values in 32 bit integers r = np.left_shift(pixels[0][:].astype(int), 8) g = np.left_shift(pixels[1][:].astype(int), 16) b = pixels[2][:].astype(int) rgb = np.bitwise_or(np.bitwise_or(r, g), b) # Update the pixels for i in range(n_pixels): self.strip.setPixelColor(i, neopixel.Color(rgb[i])) self.strip.show()
Example 28
Project: Systematic-LEDs Author: not-matt File: led.py License: MIT License | 6 votes |
def _update_pi(): """Writes new LED values to the Raspberry Pi's LED strip Raspberry Pi uses the rpi_ws281x to control the LED strip directly. This function updates the LED strip with new values. """ global pixels, _prev_pixels # Truncate values and cast to integer pixels = np.clip(pixels, 0, 255).astype(int) # Optional gamma correction p = _gamma[pixels] if config.settings["configuration"]["SOFTWARE_GAMMA_CORRECTION"] else np.copy(pixels) # Encode 24-bit LED values in 32 bit integers r = np.left_shift(p[0][:].astype(int), 8) g = np.left_shift(p[1][:].astype(int), 16) b = p[2][:].astype(int) rgb = np.bitwise_or(np.bitwise_or(r, g), b) # Update the pixels for i in range(config.settings["configuration"]["N_PIXELS"]): # Ignore pixels if they haven't changed (saves bandwidth) if np.array_equal(p[:, i], _prev_pixels[:, i]): continue strip._led_data[i] = rgb[i] _prev_pixels = np.copy(p) strip.show()
Example 29
Project: elasticintel Author: securityclippy File: test_ufunc.py License: GNU General Public License v3.0 | 6 votes |
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
Project: elasticintel Author: securityclippy File: test_umath.py License: 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)