当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python tf.strings.as_string用法及代码示例


将给定张量中的每个条目转换为字符串。

用法

tf.strings.as_string(
    input, precision=-1, scientific=False, shortest=False, width=-1,
    fill='', name=None
)

参数

  • input 一个Tensor。必须是以下类型之一:float32 , float64 , int32 , uint8 , int16 , int8 , int64 , bfloat16 , uint16 , half , uint32 , uint64 , complex64 , complex128 , bool , variant
  • precision 可选的 int 。默认为 -1 。用于浮点数的post-decimal 精度。仅在精度 > -1 时使用。
  • scientific 可选的 bool 。默认为 False 。对浮点数使用科学计数法。
  • shortest 可选的 bool 。默认为 False 。对浮点数使用最短的表示(科学或标准)。
  • width 可选的 int 。默认为 -1 。将前十进制数字填充到此宽度。适用于浮点数和整数。仅在宽度 > -1 时使用。
  • fill 可选的 string 。默认为 "" 。如果宽度 > -1 则填充的值。如果为空,则用空格填充。另一个典型值是'0'。字符串不能超过 1 个字符。
  • name 操作的名称(可选)。

返回

  • Tensor 类型为 string

支持许多数字类型和布尔值。

对于 Unicode,请参阅https://www.tensorflow.org/tutorials/representation/unicode教程。

例子:

tf.strings.as_string([3, 2])
<tf.Tensor:shape=(2,), dtype=string, numpy=array([b'3', b'2'], dtype=object)>
tf.strings.as_string([3.1415926, 2.71828], precision=2).numpy()
array([b'3.14', b'2.72'], dtype=object)

相关用法


注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.strings.as_string。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。