当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python tf.bitwise.right_shift用法及代码示例


Elementwise 计算 xy 的按位 right-shift。

用法

tf.bitwise.right_shift(
    x, y, name=None
)

参数

  • x 一个Tensor。必须是以下类型之一:int8 , int16 , int32 , int64 , uint8 , uint16 , uint32 , uint64
  • y 一个Tensor。必须与 x 具有相同的类型。
  • name 操作的名称(可选)。

返回

  • 一个Tensor。具有与 x 相同的类型。

对无符号整数类型执行逻辑移位,对有符号整数类型执行算术移位。

如果y 为负数,或大于或等于x 的宽度(以位为单位),则结果由实现定义。

例子:

import tensorflow as tf
from tensorflow.python.ops import bitwise_ops
import numpy as np
dtype_list = [tf.int8, tf.int16, tf.int32, tf.int64]

for dtype in dtype_list:
  lhs = tf.constant([-1, -5, -3, -14], dtype=dtype)
  rhs = tf.constant([5, 0, 7, 11], dtype=dtype)

  right_shift_result = bitwise_ops.right_shift(lhs, rhs)

  print(right_shift_result)

# This will print:
# tf.Tensor([-1 -5 -1 -1], shape=(4,), dtype=int8)
# tf.Tensor([-1 -5 -1 -1], shape=(4,), dtype=int16)
# tf.Tensor([-1 -5 -1 -1], shape=(4,), dtype=int32)
# tf.Tensor([-1 -5 -1 -1], shape=(4,), dtype=int64)

lhs = np.array([-2, 64, 101, 32], dtype=np.int8)
rhs = np.array([-1, -5, -3, -14], dtype=np.int8)
bitwise_ops.right_shift(lhs, rhs)
# <tf.Tensor:shape=(4,), dtype=int8, numpy=array([ -2,  64, 101,  32], dtype=int8)>

相关用法


注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.bitwise.right_shift。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。