Tensorflow的张量类型转换

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-29 23:40   95   0

目录

1、tf.to_int32()

2、tf.to_float()


1、tf.to_int32()

tf.to_int32(
    x,
    name='ToInt32'
)

将张量转换为int32类型。

参数:

  • x: 张量或稀疏张量
  • name: 操作的名称(可选)。

返回值:

  • 一种形状与x相同的张量或稀疏张量,类型为int32

可能产生的异常:

  • TypeError: If x cannot be cast to the int32.

2、tf.to_float()

将张量强制转换为float32类型。

tf.to_float(
    x,
    name='ToFloat'
)

参数:

  • x:张量或稀疏张量或索引切片。
  • name:操作的名称(可选)。

返回值:

  • 一种形状与x相同的张量或稀疏张量或索引切片,类型为float32。

可能产生的异常:

  • TypeError: If x cannot be cast to the float32.

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP