Tensorflow學習之tf.cast型別轉換函式
阿新 • • 發佈:2019-01-30
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:名稱
#將0/1轉換成bool型別
import tensorflow as tf
a = 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]