本文整理汇总了Python中numpy.bitwise_or方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.bitwise_or方法的具体用法?Python numpy.bitwise_or怎么用?Python numpy.bitwise_or使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.bitwise_or方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: labelcolormap
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [as 别名]
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
# -----------------------------------------------------------------------------
示例2: test_NotImplemented_not_returned
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [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
]
# 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)
示例3: test_NotImplemented_not_returned
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [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)
示例4: test_values
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [as 别名]
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)
示例5: label_colormap
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [as 别名]
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
示例6: set_ufunc
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [as 别名]
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)
示例7: Hilditch_skeleton
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [as 别名]
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
示例8: loadDepthMap
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [as 别名]
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
示例9: _get_slice_pixeldata
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [as 别名]
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)
示例10: loadDepthMap
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [as 别名]
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
示例11: _pack_encoded_values
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [as 别名]
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()
示例12: show
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [as 别名]
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))
示例13: show
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [as 别名]
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()
示例14: _update_pi
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_or [as 别名]
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()