本文整理匯總了Python中numpy.right_shift方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.right_shift方法的具體用法?Python numpy.right_shift怎麽用?Python numpy.right_shift使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.right_shift方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_NotImplemented_not_returned
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [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)
示例2: test_NotImplemented_not_returned
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [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_simple
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [as 別名]
def test_simple(self):
input_arr = bitarray('10' * 64)
self.chip['PIXEL_REG'][:] = input_arr
self.chip['PIXEL_REG'][0] = 0
self.chip.program_pixel_reg()
ret = self.chip['DATA'].get_data()
data0 = ret.astype(np.uint8)
data1 = np.right_shift(ret, 8).astype(np.uint8)
data = np.reshape(np.vstack((data1, data0)), -1, order='F')
bdata = np.unpackbits(data)
input_arr[0] = 0
self.assertEqual(input_arr.tolist(), bdata.tolist())
示例4: bits_strip
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [as 別名]
def bits_strip(bit_start, bit_count, value):
"""Extract specified bit from bit representation of integer value.
Parameters
----------
bit_start : int
Starting index of the bits to extract (first bit has index 0)
bit_count : int
Number of bits starting from bit_start to extract
value : int
Number from which to extract the bits
Returns
-------
int
Value of the extracted bits
"""
bit_mask = pow(2, bit_start + bit_count) - 1
return np.right_shift(np.bitwise_and(value, bit_mask), bit_start)
示例5: LCD_ShowImage
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [as 別名]
def LCD_ShowImage(self,Image,Xstart,Ystart):
if (Image == None):
return
imwidth, imheight = Image.size
if imwidth != self.width or imheight != self.height:
raise ValueError('Image must be same dimensions as display \
({0}x{1}).' .format(self.width, self.height))
img = np.asarray(Image)
pix = np.zeros((self.width,self.height,2), dtype = np.uint8)
pix[...,[0]] = np.add(np.bitwise_and(img[...,[0]],0xF8),np.right_shift(img[...,[1]],5))
pix[...,[1]] = np.add(np.bitwise_and(np.left_shift(img[...,[1]],3),0xE0),np.right_shift(img[...,[2]],3))
pix = pix.flatten().tolist()
self.LCD_SetWindows(0, 0, self.width , self.height)
GPIO.output(LCD_Config.LCD_DC_PIN, GPIO.HIGH)
for i in range(0,len(pix),4096):
LCD_Config.SPI_Write_Byte(pix[i:i+4096])
示例6: test_binary_int_broadcast_1
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [as 別名]
def test_binary_int_broadcast_1():
for op, ref in [(relay.right_shift, np.right_shift),
(relay.left_shift, np.left_shift)]:
x = relay.var("x", relay.TensorType((10, 4), "int32"))
y = relay.var("y", relay.TensorType((5, 10, 1), "int32"))
z = op(x, y)
zz = run_infer_type(z)
assert zz.checked_type == relay.TensorType((5, 10, 4), "int32")
if ref is not None:
x_shape = (10, 4)
y_shape = (5, 10, 1)
t1 = relay.TensorType(x_shape, 'int32')
t2 = relay.TensorType(y_shape, 'int32')
x_data = np.random.randint(1, 10000, size=(x_shape)).astype(t1.dtype)
y_data = np.random.randint(1, 31, size=(y_shape)).astype(t2.dtype)
func = relay.Function([x, y], z)
ref_res = ref(x_data, y_data)
for target, ctx in ctx_list():
intrp = relay.create_executor("graph", ctx=ctx, target=target)
op_res = intrp.evaluate(func)(x_data, y_data)
tvm.testing.assert_allclose(op_res.asnumpy(), ref_res)
示例7: np_float2np_bf16
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [as 別名]
def np_float2np_bf16(arr):
''' Convert a numpy array of float to a numpy array
of bf16 in uint16'''
orig = arr.view('<u4')
bias = np.bitwise_and(np.right_shift(orig, 16), 1) + 0x7FFF
return np.right_shift(orig + bias, 16).astype('uint16')
示例8: exprsco_to_rawsco
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [as 別名]
def exprsco_to_rawsco(exprsco, clock=1789773.):
rate, nsamps, exprsco = exprsco
m = exprsco[:, :3, 0]
m_zero = np.where(m == 0)
m = m.astype(np.float32)
f = 440 * np.power(2, ((m - 69) / 12))
f_p, f_tr = f[:, :2], f[:, 2:]
t_p = np.round((clock / (16 * f_p)) - 1)
t_tr = np.round((clock / (32 * f_tr)) - 1)
t = np.concatenate([t_p, t_tr], axis=1)
t = t.astype(np.uint16)
t[m_zero] = 0
th = np.right_shift(np.bitwise_and(t, 0b11100000000), 8)
tl = np.bitwise_and(t, 0b00011111111)
rawsco = np.zeros((exprsco.shape[0], 4, 4), dtype=np.uint8)
rawsco[:, :, 2:] = exprsco[:, :, 1:]
rawsco[:, :3, 0] = th
rawsco[:, :3, 1] = tl
rawsco[:, 3, 1:] = exprsco[:, 3, :]
return (clock, rate, nsamps, rawsco)
示例9: compactbit
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [as 別名]
def compactbit(b):
nSamples, nbits = b.shape
nwords = (nbits + 7) / 8
B = np.hstack([np.packbits(b[:, i*8:(i+1)*8][:, ::-1], 1)
for i in xrange(nwords)])
residue = nbits % 8
if residue != 0:
B[:, -1] = np.right_shift(B[:, -1], 8 - residue)
return B
示例10: image_to_data
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [as 別名]
def image_to_data(self, image, rotation=0):
"""Generator function to convert a PIL image to 16-bit 565 RGB bytes."""
# NumPy is much faster at doing this. NumPy code provided by:
# Keith (https://www.blogger.com/profile/02555547344016007163)
pb = np.rot90(np.array(image.convert('RGB')), rotation // 90).astype('uint8')
result = np.zeros((self._width, self._height, 2), dtype=np.uint8)
result[..., [0]] = np.add(np.bitwise_and(pb[..., [0]], 0xF8), np.right_shift(pb[..., [1]], 5))
result[..., [1]] = np.add(np.bitwise_and(np.left_shift(pb[..., [1]], 3), 0xE0), np.right_shift(pb[..., [2]], 3))
return result.flatten().tolist()
示例11: test_shift
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [as 別名]
def test_shift():
# explicit specify the output type
verify_broadcast_binary_ele(
(2, 1, 2), None, topi.right_shift, np.right_shift,
dtype="int32", rhs_min=0, rhs_max=32)
verify_broadcast_binary_ele(
(1, 2, 2), (2,), topi.left_shift, np.left_shift,
dtype="int32", rhs_min=0, rhs_max=32)
verify_broadcast_binary_ele(
(1, 2, 2), (2,), topi.left_shift, np.left_shift,
dtype="int8", rhs_min=0, rhs_max=32)
示例12: run
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [as 別名]
def run(self, tensor: np.ndarray, data_format: str = 'NHWC') -> np.ndarray:
"""Pack a tensor.
Args:
tensor (np.ndarray): Input tensor.
data_format (str): Order of dimension. This defaults to 'NHWC', where 'N' is
the number of kernels, 'H' and 'W' are the height and
width, and 'C' is the depth / the number of channels.
Returns:
np.ndarray: Quantized tensor.
"""
wordsize = self.wordsize
if (tensor >= (2 ** self.bitwidth)).any():
raise ValueError("all value of input tensor must be less than bit width ({})".format(self.bitwidth))
output_size = tensor.size // wordsize
output_size += 1 if tensor.size % wordsize != 0 else 0
output_size *= self.bitwidth
tensor_flat = tensor.flatten(order='C').astype(np.uint32)
output = np.zeros(output_size, dtype=np.uint32)
oi = 0
for i in range(0, tensor.size, wordsize):
if i + wordsize < tensor.size:
sliced_tensor = tensor_flat[i:i + wordsize]
else:
sliced_tensor = tensor_flat[i:]
for _ in range(0, self.bitwidth):
output[oi] = self._pack_to_word(np.bitwise_and(sliced_tensor, 1))
oi += 1
sliced_tensor = np.right_shift(sliced_tensor, 1)
return output.reshape([1, output_size])
示例13: _rgb_integers_to_components
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [as 別名]
def _rgb_integers_to_components(self, rgb_integers):
red_mask = 0x00FF0000
green_mask = 0x0000FF00
blue_mask = 0x000000FF
masks = np.asarray([[red_mask, green_mask, blue_mask]])
masked_rgb_components = np.bitwise_and(rgb_integers, masks)
red_shifted = np.right_shift(masked_rgb_components[:,0], 16)
green_shifted = np.right_shift(masked_rgb_components[:,1], 8)
blue_shifted = np.right_shift(masked_rgb_components[:,2], 0)
return np.array([red_shifted, green_shifted, blue_shifted]).transpose()
示例14: _transform_color_int_to_rgba
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [as 別名]
def _transform_color_int_to_rgba(np_values):
np_values[np_values == gxapi.iDUMMY] = 0
a = (np.right_shift(np_values, 24) & 0xFF).astype(np.uint8)
b = (np.right_shift(np_values, 16) & 0xFF).astype(np.uint8)
g = (np.right_shift(np_values, 8) & 0xFF).astype(np.uint8)
r = (np_values & 0xFF).astype(np.uint8)
# the values for color grids actually do not contain alphas but just
# 0 or 1 to indicate if the color is valid or not
a[a > 0] = 255
return np.array([r, g, b, a]).transpose()
示例15: load_gated
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import right_shift [as 別名]
def load_gated(root_dir, sample, slice):
path = os.path.join(root_dir, 'gated{}_10bit'.format(slice), sample + '.png')
img = cv2.imread(path, -1)
img = np.right_shift(img, 2).astype(np.uint8) # convert from 10bit to 8bit
return img