为了便于大家查询,也方便自己记忆,现将tensorflow中的常用函数整理如下:
计算最大值:
tf.reduce_max(input_tensor, reduction_indices=None)
计算平均值
tf.reduce_mean(input_tensor, reduction_indices=None)
参数1–input_tensor:待求值的tensor。
如
# 'x' is [[1., 2.]
# [3., 4.]]
调用求平均值函数如下:
对所有元素求平均值:
import tensorflow as tf
v=tf.constant([[1.0,2.0],[3.0,4.0]])
result=tf.reduce_mean(v)
sess=tf.InteractiveSession()
print(result.eval())
sess.close()
---> 2.5
对每列求平均值:
import tensorflow as tf
v=tf.constant([[1.0,2.0],[3.0,4.0]])
result=tf.reduce_mean(v,0)
sess=tf.InteractiveSession()
print(result.eval())
sess.close()
--> [ 2. 3.]
对每行求平均值:
import tensorflow as tf
v=tf.constant([[1.0,2.0],[3.0,4.0]])
result=tf.reduce_mean(v,1)
sess=tf.InteractiveSession()
print(result.eval())
sess.close()
--> [ 1.5 3.5]
定义形参,运行时赋值
tf.placeholder(dtype,shape=None,name=None)
dtype:数据类型,通常 dtype=tf.float32,tf.float64
shape:数据类型,一维或者多维
name:名称,不赘述
1597

被折叠的 条评论
为什么被折叠?



