tensorflow中的常用函数(不断更新)

来源:互联网 发布:手机淘宝详情制作软件 编辑:程序博客网 时间:2024/06/13 22:02

为了便于大家查询,也方便自己记忆,现将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 tfv=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 tfv=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 tfv=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:名称,不赘述

原创粉丝点击