tf.bitwise.left_shift
Stay organized with collections
Save and categorize content based on your preferences.
Elementwise computes the bitwise left-shift of x
and y
.
tf.bitwise.left_shift(
x: Annotated[Any, TV_LeftShift_T],
y: Annotated[Any, TV_LeftShift_T],
name=None
) -> Annotated[Any, TV_LeftShift_T]
If y
is negative, or greater than or equal to the width of x
in bits the
result is implementation defined.
Example:
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)>
Args |
x
|
A Tensor . Must be one of the following types: int8 , int16 , int32 , int64 , uint8 , uint16 , uint32 , uint64 .
|
y
|
A Tensor . Must have the same type as x .
|
name
|
A name for the operation (optional).
|
Returns |
A Tensor . Has the same type as x .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.bitwise.left_shift\n\n\u003cbr /\u003e\n\nElementwise computes the bitwise left-shift of `x` and `y`.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.bitwise.left_shift`](https://www.tensorflow.org/api_docs/python/tf/bitwise/left_shift)\n\n\u003cbr /\u003e\n\n tf.bitwise.left_shift(\n x: Annotated[Any, TV_LeftShift_T],\n y: Annotated[Any, TV_LeftShift_T],\n name=None\n ) -\u003e Annotated[Any, TV_LeftShift_T]\n\nIf `y` is negative, or greater than or equal to the width of `x` in bits the\nresult is implementation defined.\n\n#### Example:\n\n import tensorflow as tf\n from tensorflow.python.ops import bitwise_ops\n import numpy as np\n dtype_list = [tf.int8, tf.int16, tf.int32, tf.int64]\n\n for dtype in dtype_list:\n lhs = tf.constant([-1, -5, -3, -14], dtype=dtype)\n rhs = tf.constant([5, 0, 7, 11], dtype=dtype)\n\n left_shift_result = bitwise_ops.left_shift(lhs, rhs)\n\n print(left_shift_result)\n\n # This will print:\n # tf.Tensor([ -32 -5 -128 0], shape=(4,), dtype=int8)\n # tf.Tensor([ -32 -5 -384 -28672], shape=(4,), dtype=int16)\n # tf.Tensor([ -32 -5 -384 -28672], shape=(4,), dtype=int32)\n # tf.Tensor([ -32 -5 -384 -28672], shape=(4,), dtype=int64)\n\n lhs = np.array([-2, 64, 101, 32], dtype=np.int8)\n rhs = np.array([-1, -5, -3, -14], dtype=np.int8)\n bitwise_ops.left_shift(lhs, rhs)\n # \u003ctf.Tensor: shape=(4,), dtype=int8, numpy=array([ -2, 64, 101, 32], dtype=int8)\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|---------------------------------------------------------------------------------------------------------------------------|\n| `x` | A `Tensor`. Must be one of the following types: `int8`, `int16`, `int32`, `int64`, `uint8`, `uint16`, `uint32`, `uint64`. |\n| `y` | A `Tensor`. Must have the same type as `x`. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor`. Has the same type as `x`. ||\n\n\u003cbr /\u003e"]]