Tensorflow学习之tf.cast类型转换函数

来源:互联网 发布:阿里云账号注销解绑 编辑:程序博客网 时间:2024/06/16 17:27

tf.cast(x, dtype, name=None) //此函数是类型转换函数,把x的类型转换成dtype指定的类型

Args:x: A Tensor or SparseTensor.dtype: The destination type.name: A name for the operation (optional).Returns:A Tensor or SparseTensor with same shape as x.Raises:TypeError: If x cannot be cast to the dtype.


参数
  • x:输入
  • dtype:转换目标类型
  • name:名称
返回
     Tensor

例子
#将0/1转换成bool类型import tensorflow as tfa = tf.Variable([1,0,0,1,1])b = tf.cast(a,dtype=tf.bool)sess = tf.Session()sess.run(tf.initialize_all_variables())print(sess.run(b))#[ True False False  True  True]



原创粉丝点击