当前位置: 首页>>代码示例>>Python>>正文


Python numpy.left_shift方法代码示例

本文整理汇总了Python中numpy.left_shift方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.left_shift方法的具体用法?Python numpy.left_shift怎么用?Python numpy.left_shift使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy的用法示例。


在下文中一共展示了numpy.left_shift方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_NotImplemented_not_returned

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_ufunc.py

示例2: test_NotImplemented_not_returned

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_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) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:22,代码来源:test_ufunc.py

示例3: show

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_shift [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)) 
开发者ID:TobKra96,项目名称:music_led_strip_control,代码行数:27,代码来源:output.py

示例4: show

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_shift [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() 
开发者ID:not-matt,项目名称:Systematic-LEDs,代码行数:21,代码来源:devices.py

示例5: _update_pi

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_shift [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() 
开发者ID:not-matt,项目名称:Systematic-LEDs,代码行数:26,代码来源:led.py

示例6: LCD_ShowImage

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_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]) 
开发者ID:onlaj,项目名称:Piano-LED-Visualizer,代码行数:18,代码来源:LCD_1in44.py

示例7: _update_pi

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_shift [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.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.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]
        strip._led_data[i] = int(rgb[i])
    _prev_pixels = np.copy(p)
    strip.show() 
开发者ID:scottlawsonbc,项目名称:audio-reactive-led-strip,代码行数:27,代码来源:led.py

示例8: test_binary_int_broadcast_1

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_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) 
开发者ID:apache,项目名称:incubator-tvm,代码行数:25,代码来源:test_op_level4.py

示例9: decode_4bit

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_shift [as 别名]
def decode_4bit(words):
    """Decode 4-bit data.

    For a given int8 byte containing bits 76543210,
    the first sample is in 3210, the second in 7654, and both are interpreted
    as signed 4-bit integers.
    """
    # left_shift(byte[:,np.newaxis], shift40):  [3210xxxx, 76543210]
    split = np.left_shift(words[:, np.newaxis], shift40).ravel()
    # right_shift(..., 4):                      [33333210, 77777654]
    # so least significant bits go first.
    split >>= 4
    return split.astype(np.float32) 
开发者ID:mhvk,项目名称:baseband,代码行数:15,代码来源:payload.py

示例10: rawsco_to_exprsco

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_shift [as 别名]
def rawsco_to_exprsco(rawsco, midi_valid_range=(21, 108)):
  clock, rate, nsamps, rawsco = rawsco
  assert rate == 44100
  assert rawsco.shape[0] == nsamps

  nsamps = rawsco.shape[0]

  t = rawsco[:, :3, :2].astype(np.uint16)
  t = np.left_shift(t[:, :, 0], 8) + t[:, :, 1]
  t = t.astype(np.float32)

  t_p, t_tr = t[:, :2], t[:, 2:]

  f_p = clock / (16 * (t_p + 1))
  f_tr = clock / (32 * (t_tr + 1))
  f = np.concatenate([f_p, f_tr], axis=1)

  m = 69 + (12 * np.log(f / 440)) / np.log(2)
  m = np.round(m)

  # Clip notes to midi range
  m[np.where(m < midi_valid_range[0])] = 0
  m[np.where(m > midi_valid_range[1])] = 0
  m = m.astype(np.uint8)

  # Create output score
  exprsco = np.zeros((nsamps, 4, 3), dtype=np.uint8)

  # Set notes
  exprsco[:, :3, 0] = m
  exprsco[:, 3, 0] = rawsco[:, 3, 1]

  # Set velocity
  exprsco[:, :, 1] = np.where(exprsco[:, :, 0] > 0, rawsco[:, :, 2], 0)

  # Set extra
  exprsco[:, :, 2] = rawsco[:, :, 3]

  return (rate, nsamps, exprsco) 
开发者ID:chrisdonahue,项目名称:nesmdb,代码行数:41,代码来源:exprsco.py

示例11: image_to_data

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_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() 
开发者ID:pimoroni,项目名称:st7789-python,代码行数:12,代码来源:__init__.py

示例12: __getitem__

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_shift [as 别名]
def __getitem__(self, index):
        #self.paths['images'][index]
        # print self.opt.scale,self.opt.flip,self.opt.crop,self.opt.colorjitter
        img = np.asarray(Image.open(self.paths_dict['images'][index]))#.astype(np.uint8)
        HHA = np.asarray(Image.open(self.paths_dict['HHAs'][index]))[:,:,::-1]
        seg = np.asarray(Image.open(self.paths_dict['segs'][index])).astype(np.uint8)-1
        depth = np.asarray(Image.open(self.paths_dict['depths'][index])).astype(np.uint16)

        assert (img.shape[0]==HHA.shape[0]==seg.shape[0]==depth.shape[0])
        assert (img.shape[1]==HHA.shape[1]==seg.shape[1]==depth.shape[1])

        depth = np.bitwise_or(np.right_shift(depth,3),np.left_shift(depth,16-3))
        depth = depth.astype(np.float32)/120. # 1/5 * depth




        params = get_params_sunrgbd(self.opt, seg.shape, maxcrop=.7)
        depth_tensor_tranformed = transform(depth, params, normalize=False,istrain=self.opt.isTrain)
        seg_tensor_tranformed = transform(seg, params, normalize=False,method='nearest',istrain=self.opt.isTrain)
        if self.opt.inputmode == 'bgr-mean':
            img_tensor_tranformed = transform(img, params, normalize=False, istrain=self.opt.isTrain, option=1)
            HHA_tensor_tranformed = transform(HHA, params, normalize=False, istrain=self.opt.isTrain, option=2)
        else:
            img_tensor_tranformed = transform(img, params, istrain=self.opt.isTrain, option=1)
            HHA_tensor_tranformed = transform(HHA, params, istrain=self.opt.isTrain, option=2)


        # print img_tensor_tranformed
        # print(np.unique(depth_tensor_tranformed.numpy()).shape)
        # print img_tensor_tranformed.size()
        return {'image':img_tensor_tranformed,
                'depth':depth_tensor_tranformed,
                'seg': seg_tensor_tranformed,
                'HHA': HHA_tensor_tranformed,
                'imgpath': self.paths_dict['segs'][index]} 
开发者ID:laughtervv,项目名称:DepthAwareCNN,代码行数:38,代码来源:sunrgbd_dataset.py

示例13: load_spc

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_shift [as 别名]
def load_spc(fname):
    """Load data from Becker&Hickl SPC files.

    Returns:
        3 numpy arrays: timestamps, detector, nanotime
    """
    spc_dtype = np.dtype([('field0', '<u2'), ('b', '<u1'), ('c', '<u1'),
                          ('a', '<u2')])
    data = np.fromfile(fname, dtype=spc_dtype)

    nanotime =  4095 - np.bitwise_and(data['field0'], 0x0FFF)
    detector = data['c']

    # Build the macrotime (timestamps) using in-place operation for efficiency
    timestamps = data['b'].astype('int64')
    np.left_shift(timestamps, 16, out=timestamps)
    timestamps += data['a']

    # extract the 13-th bit from data['field0']
    overflow = np.bitwise_and(np.right_shift(data['field0'], 13), 1)
    overflow = np.cumsum(overflow, dtype='int64')

    # Add the overflow bits
    timestamps += np.left_shift(overflow, 24)

    return timestamps, detector, nanotime 
开发者ID:tritemio,项目名称:FRETBursts,代码行数:28,代码来源:spcreader.py

示例14: test_shift

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_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) 
开发者ID:mlperf,项目名称:training_results_v0.6,代码行数:15,代码来源:test_topi_broadcast.py

示例15: posterize

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import left_shift [as 别名]
def posterize(img, bits):
    """Posterize an image (reduce the number of bits for each color channel)

    Args:
        img (ndarray): Image to be posterized.
        bits (int): Number of bits (1 to 8) to use for posterizing.

    Returns:
        ndarray: The posterized image.
    """
    shift = 8 - bits
    img = np.left_shift(np.right_shift(img, shift), shift)
    return img 
开发者ID:open-mmlab,项目名称:mmcv,代码行数:15,代码来源:photometric.py


注:本文中的numpy.left_shift方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。