TensorFlow tensor的类型和形状转化

2022年12月23日10:26:26

类型转化

 tf.string_to_number(string_tensor, out_type=None, name=None): 将字符串转化为tf.float32(默认)和tf.int32

 tf.to_double(x, name='ToDouble'):转化为tf.float64

 tf.to_float(x, name='ToFloat'):转化为tf.float32

 tf.to_int32(x, name='ToInt32'):转化为tf.int32

 tf.to_int64(x, name='ToInt64'):转化为tf.int64

 tf.cast(x, dtype, name=None):转化为dtype指定的类型

形状转化

 tf.reshape(tensor, shape, name=None):转化为新shape,若有一个维度设置为-1,会自动推导

  • 作者:Eric_LH
  • 原文链接:https://blog.csdn.net/Eric_LH/article/details/82631392
    更新时间:2022年12月23日10:26:26 ,共 369 字。