Elementwise 計算 x
和 y
的按位 left-shift。
用法
tf.raw_ops.LeftShift(
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)
left_shift_result = bitwise_ops.left_shift(lhs, rhs)
print(left_shift_result)
# This will print:
# tf.Tensor([ -32 -5 -128 0], shape=(4,), dtype=int8)
# tf.Tensor([ -32 -5 -384 -28672], shape=(4,), dtype=int16)
# tf.Tensor([ -32 -5 -384 -28672], shape=(4,), dtype=int32)
# tf.Tensor([ -32 -5 -384 -28672], 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.left_shift(lhs, rhs)
# <tf.Tensor:shape=(4,), dtype=int8, numpy=array([ -2, 64, 101, 32], dtype=int8)>
相關用法
- Python tf.raw_ops.LessEqual用法及代碼示例
- Python tf.raw_ops.Less用法及代碼示例
- Python tf.raw_ops.LogSoftmax用法及代碼示例
- Python tf.raw_ops.L2Loss用法及代碼示例
- Python tf.raw_ops.LSTMBlockCell用法及代碼示例
- Python tf.raw_ops.LogicalOr用法及代碼示例
- Python tf.raw_ops.Log1p用法及代碼示例
- Python tf.raw_ops.LogicalNot用法及代碼示例
- Python tf.raw_ops.Lgamma用法及代碼示例
- Python tf.raw_ops.LRN用法及代碼示例
- Python tf.raw_ops.Log用法及代碼示例
- Python tf.raw_ops.ListDiff用法及代碼示例
- Python tf.raw_ops.LogicalAnd用法及代碼示例
- Python tf.raw_ops.LinSpace用法及代碼示例
- Python tf.raw_ops.TPUReplicatedInput用法及代碼示例
- Python tf.raw_ops.Bitcast用法及代碼示例
- Python tf.raw_ops.SelfAdjointEigV2用法及代碼示例
- Python tf.raw_ops.BatchMatMul用法及代碼示例
- Python tf.raw_ops.OneHot用法及代碼示例
- Python tf.raw_ops.ResourceScatterNdSub用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.raw_ops.LeftShift。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。