tf.reduce_sum()_tf.reduce_mean()_tf.reduce_max()
根据官方文档:
reduce_sum应该理解为压缩求和,用于降维
Args:
input_tensor: The tensor to reduce. Should have numeric type. #输入axis: The dimensions to reduce. IfNone(the default), reduces all dimensions. Must be in the range (rank(input_tensor), rank(input_tensor)).#取0第一维,取1第二维,取-1最后一维keepdims: If true, retains reduced dimensions with length 1.#按照原来的维度name: A name for the operation (optional).reduction_indices: The old (deprecated) name for axis.#axis的原来的名字keep_dims: Deprecated alias forkeepdims.import tensorflow as tf
import numpy as np x = tf.constant([[1,1,1],[2,2,2]])
with tf.Session() as sess:
print(sess.run(tf.reduce_sum(x))) #所有求和
print(sess.run(tf.reduce_sum(x,0))) #按 列 求和
print(sess.run(tf.reduce_sum(x,1))) #按 行 求和
print(sess.run(tf.reduce_sum(x,1,keepdims=True))) #按维度 行 求和
print(sess.run(tf.reduce_sum(x,[0,1]))) #行列求和
print(sess.run(tf.reduce_sum(x,reduction_indices=[1])))输出结果:
9
[3 3 3]
[3 6]
[[3]
[6]]
9
[3 6]求最大值tf.reduce_max(input_tensor, reduction_indices=None, keep_dims=False, name=None)
求平均值tf.reduce_mean(input_tensor, reduction_indices=None, keep_dims=False, name=None)
参数1--input_tensor:待求值的tensor。
参数2--reduction_indices:在哪一维上求解。
参数(3)(4)可忽略
import tensorflow as tf
import numpy as np x = tf.constant([[1,2],[3,4]])
with tf.Session() as sess:
print(sess.run(tf.reduce_mean(x))) #所有求平均
print(sess.run(tf.reduce_mean(x, 0))) #按 列 求和
print(sess.run( tf.reduce_mean(x, 1)))#按行求平均
print(sess.run(tf.reduce_max(x)))
print(sess.run(tf.reduce_max(x, 0)))
print(sess.run(tf.reduce_max(x, 1)))
###############输出##########
2
[2 3]
[1 3]
4
[3 4]
[2 4]
tf.reduce_sum()_tf.reduce_mean()_tf.reduce_max()的更多相关文章
- tf.reduce_sum()函数
1234567reduce_sum 是 tensor 内部求和的工具.其参数中: input_tensor 是要求和的 tensor axis 是要求和的 rank,如果为 none,则表示所有 ra ...
- TensorFlow函数:tf.reduce_sum
tf.reduce_sum 函数 reduce_sum ( input_tensor , axis = None , keep_dims = False , name = None , reducti ...
- tf.reduce_sum tensorflow维度上的操作
tensorflow中有很多在维度上的操作,本例以常用的tf.reduce_sum进行说明.官方给的api reduce_sum( input_tensor, axis=None, keep_dims ...
- tf.reduce_sum函数
>>> x=[[1,2,3],[23,13,213]] >>> xx=tf.reduce_sum(x) >>> sess.run(xx) 255 ...
- tf.reduce_sum() and tf.where()的用法
import tensorflow as tfimport numpy as npsess=tf.Session()a=np.ones((5,6))c=tf.cast(tf.reduce_sum(a, ...
- tf.reduce_sum()
#axis 表示在哪个维度进行sum操作,不写代表所有维 #keep_dims 是否保留原始数据维度 reduce_sum( input_tensor, axis=None, keep_dims=Fa ...
- 理解 tf.reduce_sum(),以及tensorflow的维axis
易错点:注意带上参数axis,否则的话,默认对全部元素求和,返回一个数值int 参考:https://www.jianshu.com/p/30b40b504bae tf.reduce_sum( inp ...
- TFboy养成记 tf.cast,tf.argmax,tf.reduce_sum
referrence: 莫烦视频 先介绍几个函数 1.tf.cast() 英文解释: 也就是说cast的直译,类似于映射,映射到一个你制定的类型. 2.tf.argmax 原型: 含义:返回最大值所在 ...
- tensorflow中 tf.reduce_mean函数
tf.reduce_mean 函数用于计算张量tensor沿着指定的数轴(tensor的某一维度)上的的平均值,主要用作降维或者计算tensor(图像)的平均值. reduce_mean(input_ ...
随机推荐
- PHP中类型约束
类型约束 什么叫类型约束? 就是要求某个变量只能使用(接收,存储)某种指定的数据类型: php属于“弱类型语言”,通常不支持类型约束: 相应的,强类型语言,类型约束却是其“基本特征”. php中,只支 ...
- LoadRunner录制用户操作
先说明一点,使用录制的手段拿到的测试脚本和工程师自己编写的测试脚本其实是一样的,不要觉得录制的方式low,而自己编写脚本就显得高大上,这是不对的.除非工程师本身对开发们写的代码逻辑很熟,对业务上的各个 ...
- BZOJ 1835 基站选址(DP+线段树)
# include <cstdio> # include <cstring> # include <cstdlib> # include <iostream& ...
- 【uoj#175】新年的网警 结论题+Hash
题目描述 给出一张 $n$ 个点 $m$ 条边的无向连通图,每条边的边权为1.对于每个点 $i$ ,问是否存在另一个点 $j$ ,使得对于任意一个不为 $i$ 或 $j$ 的点 $k$ ,$i$ 到 ...
- [三]SpringBoot 之 热部署
如下配置 <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring ...
- (转)java web自定义分页标签
转载至http://liuxi1024.iteye.com/blog/707784 效果如图: 1.JSP规范1.1版本后增加了自定义标签库.实现自定义标签的步骤 (1)开发自定义标签处理类. (2) ...
- 51nod1222 最小公倍数计数 莫比乌斯反演 数学
求$\sum_{i = 1}^{n} \sum_{j = 1}^{i} [lcm(i, j) \le n]$因为这样不好求,我们改成求$\sum_{i = 1}^{n} \sum_{j = 1}^{n ...
- [USACO4.1]麦香牛块Beef McNuggets 题解报告
题目描述 农夫布朗的奶牛们正在进行斗争,因为它们听说麦当劳正在考虑引进一种新产品:麦香牛块.奶牛们正在想尽一切办法让这种可怕的设想泡汤.奶牛们进行斗争的策略之一是"劣质的包装".& ...
- 服务器启动脚本 /etc/rc.local
#启动php-frm/home/www/php/sbin/php-fpm #启动搜索引擎/home/www/se/bin/xs-ctl.sh start #启动lighttpd/home/www/li ...
- yd的拔钉子之路之 POI 2017
写在前面的一些话 如果我NOIP没退役,这大概会写成一个系列吧,所以这算是系列的开始,要写一些奇怪的东西? 首先解释下什么叫“拔钉子”,其实就是在钉子上做题嘛......至于钉子具体是个什么东西就当面 ...