1. 变量类型转换
a. A=tf.to_xxxx(B):将变量转换成指定类型:
格式:
new_variable=tf.to_xxx(variable):
有以下函数可用:
tf.string_to_number(string_tensor, out_type=None, name=None)
tf.to_double(x, name='ToDouble')
tf.to_float(x, name='ToFloat')
tf.to_bfloat16(x, name='ToBFloat16')
tf.to_int32(x, name='ToInt32')
tf.to_int64(x, name='ToInt64')
tf.cast(x, dtype, name=None)
b. A=tf.cast(A,dtype): 用cast函数,指定类型进行转换:
附: tf dtype类型
有符号整型:tf.int8(8位整数),tf.int16(16位整数),tf.int32(32位整数),tf.int64(64位整数)
无符号整型:tf.uint8(8位无符号整数),tf.uint16(16位无符号整数)
浮点型:tf.float16(16位浮点数),tf.float32(32位浮点数),tf.float64(64位浮点数),tf.double(等同于tf.float64)
字符串型:tf.string(字符串)
布尔型:tf.bool(布尔型)
复数型:tf.complex64(64位复数),tf.complex128(128位复数)
2. 矩阵运算:
a. 点对点乘: C=A*B
A和B有同样的结构,对应元素相乘,获得对应结构的C
b. 矩阵乘: C=tf.matmul(A,B)
A和B以矩阵运算规则进行相乘
note:
运算次数是运算时间的主要因素,矩阵运算可以加快速度