tensorflow 基本操作

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:

运算次数是运算时间的主要因素,矩阵运算可以加快速度

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值