a #<tf.Tensor: shape=(4, 2), dtype=float32, numpy= array([[ 0.491424 , 0.6428182 ], [ 2.247138 , 0.2008341 ], [ 0.93056387, 0.01603121], [ 0.33425295, -1.1971117 ]], dtype=float32)> tf.cast(a,dtype=tf.float64) a #<tf.Tensor: shape=(4, 2), dtype=float32, numpy= array([[ 0.491424 , 0.6428182 ], [ 2.247138 , 0.2008341 ], [ 0.93056387, 0.01603121], [ 0.33425295, -1.1971117 ]], dtype=float32)> tf.reduce_min(a) #<tf.Tensor: shape=(), dtype=float32, numpy=-1.1971117> tf.reduce_max(a) #<tf.Tensor: shape=(), dtype=float32, numpy=2.247138> #axis = 0 代表纵向,axis = 1 代表横向 tf.reduce_mean(a) #<tf.Tensor: shape=(), dtype=float32, numpy=0.45824385> tf.reduce_mean(a,axis=0) #<tf.Tensor: shape=(2,), dtype=float32, numpy=array([ 1.0008447 , -0.08435705], dtype=float32)> tf.reduce_mean(a,axis=1) #<tf.Tensor: shape=(4,), dtype=float32, numpy=array([ 0.5671211 , 1.223986 , 0.47329754, -0.4314294 ], dtype=float32)>
#tf.reduce_sum()同理
tf.Varible
tf.add,tf.substract,tf.multiply,tf.divide
tf.square,tf.pow,tf.sqrt
tf.matmul
features = tf.constant([12,23,10,17]) labels = tf.constant([0, 1, 1, 0]) dataset = tf.data.Dataset.from_tensor_slices((features, labels)) dataset #<TensorSliceDataset shapes: ((), ()), types: (tf.int32, tf.int32)> for i in dataset: print(i) (<tf.Tensor: shape=(), dtype=int32, numpy=12>, <tf.Tensor: shape=(), dtype=int32, numpy=0>) (<tf.Tensor: shape=(), dtype=int32, numpy=23>, <tf.Tensor: shape=(), dtype=int32, numpy=1>) (<tf.Tensor: shape=(), dtype=int32, numpy=10>, <tf.Tensor: shape=(), dtype=int32, numpy=1>) (<tf.Tensor: shape=(), dtype=int32, numpy=17>, <tf.Tensor: shape=(), dtype=int32, numpy=0>)