TensorFlow是Google設計的開源python庫,用於開發機器學習模型和深度學習神經網絡。
bitcast()是張量流庫中的方法,用於將張量從一種類型轉換為另一種類型。它不會複製數據。
用法: tf.bitcast( input, type, name ) Arguments: 1. input: It is the Tensor and the allowed type for this tensor are bfloat16, half, float32, float64, int64, int32, uint8, uint16, uint32, uint64, int8, int16, complex64, complex128, qint8, quint8, qint16, quint16, qint32. 2. type:It defines the dtype in which input need to be bitcasted. 3. name: It is an optional argument. It is used to give a name to operation. 返回: It returns a tensor of type type.
注意:位廣播不能用於將實際dtype轉換為複雜dtype。它將引發InvalidArgumentError。
範例1:
Python3
# importing the library
import tensorflow
# initializing the constant tensor of dtype unit32
a = tensorflow.constant(0xffffffff, dtype=tensorflow.uint32)
# Checking the initialized tensor
print('a:',a)
# bitcasting to dtype unit8
b = tensorflow.bitcast(a, tensorflow.uint8)
# Checking the bitcasted tensor
print('b:',b)
輸出:
a:tf.Tensor(4294967295, shape=(), dtype=uint32) b:tf.Tensor([255 255 255 255], shape=(4,), dtype=uint8)
範例2:
本示例嘗試將實數dtype轉換為複雜dtype
Python3
# importing the library
import tensorflow
# initializing the constant tensor of dtype unit32
a = tensorflow.constant(0xffffffff, dtype=tensorflow.uint32)
# Checking the initialized tensor
print('a:',a)
# bitcasting to dtype complex128
b = tensorflow.bitcast(a, tensorflow.complex128)
輸出:
相關用法
- Python os.dup()用法及代碼示例
- Python next()用法及代碼示例
- Python set()用法及代碼示例
- Python sympy.gcd()用法及代碼示例
- Python PIL ImageOps.fit()用法及代碼示例
- Python PIL getbands()用法及代碼示例
- Python sympy.Pow()用法及代碼示例
- Python PIL Image.new()用法及代碼示例
- Python sys.setrecursionlimit()用法及代碼示例
- Python PIL UnsahrpMask()用法及代碼示例
- Python sympy.lcm()用法及代碼示例
- Python PIL getpixel()用法及代碼示例
- Python Pandas.cut()用法及代碼示例
- Python sys.getrecursionlimit()用法及代碼示例
- Python os.strerror()用法及代碼示例
注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python | tensorflow.bitcast() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。