#布尔类型
import tensorflow as tf
a = tf.constant(True)
a
<tf.Tensor: id=11, shape=(), dtype=bool, numpy=True>
import tensorflow as tf
a = tf.constant([True, False])
a
<tf.Tensor: id=12, shape=(2,), dtype=bool, numpy=array([ True, False])>
import tensorflow as tf
a = tf.constant(True)
a == True #仅数值比较
<tf.Tensor: id=15, shape=(), dtype=bool, numpy=True>
import tensorflow as tf
a = tf.constant(True)
a is True #TF布尔类型张量与python布尔类型比较
False
#数值精度
import tensorflow as tf
tf.constant(123456789, dtype = tf.int16)
<tf.Tensor: id=17, shape=(), dtype=int16, numpy=-13035>
import tensorflow as tf
a = tf.constant(123456789, dtype = tf.int32)
b = tf.constant(123456789, dtype = tf.int16)
a,b
(<tf.Tensor: id=25, shape=(), dtype=int32, numpy=123456789>,
<tf.Tensor: id=26, shape=(), dtype=int16, numpy=-13035>)
import tensorflow as tf
import numpy as np
a = tf.constant(np.pi, dtype = tf.float32)
b = tf.constant(np.pi, dtype = tf.float64)
print(a)
print(b)
tf.Tensor(3.1415927, shape=(), dtype=float32)
tf.Tensor(3.141592653589793, shape=(), dtype=float64)