根据官方文档:

reduce_sum应该理解为压缩求和,用于降维

tf.reduce_sum(input_tensor,axis=None,keepdims=None,name=None,reduction_indices=None,keep_dims=None)

Args:

  • input_tensor: The tensor to reduce. Should have numeric type. #输入
  • axis: The dimensions to reduce. If None (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 for keepdims.
    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()的更多相关文章

  1. tf.reduce_sum()函数

    1234567reduce_sum 是 tensor 内部求和的工具.其参数中: input_tensor 是要求和的 tensor axis 是要求和的 rank,如果为 none,则表示所有 ra ...

  2. TensorFlow函数:tf.reduce_sum

    tf.reduce_sum 函数 reduce_sum ( input_tensor , axis = None , keep_dims = False , name = None , reducti ...

  3. tf.reduce_sum tensorflow维度上的操作

    tensorflow中有很多在维度上的操作,本例以常用的tf.reduce_sum进行说明.官方给的api reduce_sum( input_tensor, axis=None, keep_dims ...

  4. tf.reduce_sum函数

    >>> x=[[1,2,3],[23,13,213]] >>> xx=tf.reduce_sum(x) >>> sess.run(xx) 255 ...

  5. 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, ...

  6. tf.reduce_sum()

    #axis 表示在哪个维度进行sum操作,不写代表所有维 #keep_dims 是否保留原始数据维度 reduce_sum( input_tensor, axis=None, keep_dims=Fa ...

  7. 理解 tf.reduce_sum(),以及tensorflow的维axis

    易错点:注意带上参数axis,否则的话,默认对全部元素求和,返回一个数值int 参考:https://www.jianshu.com/p/30b40b504bae tf.reduce_sum( inp ...

  8. TFboy养成记 tf.cast,tf.argmax,tf.reduce_sum

    referrence: 莫烦视频 先介绍几个函数 1.tf.cast() 英文解释: 也就是说cast的直译,类似于映射,映射到一个你制定的类型. 2.tf.argmax 原型: 含义:返回最大值所在 ...

  9. tensorflow中 tf.reduce_mean函数

    tf.reduce_mean 函数用于计算张量tensor沿着指定的数轴(tensor的某一维度)上的的平均值,主要用作降维或者计算tensor(图像)的平均值. reduce_mean(input_ ...

随机推荐

  1. 因为NLS_LANG 造成 Oracle数据库丢失 中文字符集兼容问题的处理.

    接着上一封blog. 因为sqlplus的 乱码问题 我修改了 注册表里面 NLS_LANG 的 value值.主要改动为: NLS_LANG source: SIMPLIFIED CHINESE_C ...

  2. layabox 3d 入手

    最近受到打击了,3d效果远比2d效果好. 问题 laya3d 有正交相机没有? Laya.Sprite3D.load(XX.lh);   克隆Laya.Sprite3D.instantiate Lay ...

  3. Building simple plug-ins system for ASP.NET Core(转)

    Recently I built plug-ins support to my TemperatureStation IoT solution web site. The code for .NET ...

  4. ARP(Adress Resolution Protocol): 地址解析协议

    地址解析协议(Address Resolution Protoclol),其基本功能为通过目标设备的IP地址,查询目标设备的MAC地址,以保证通信的顺利.它是IPV4中网络层必不可少的协议.不过在IP ...

  5. 分页---Vue+.net+bootstrap实现

    通过学习Vue,的确觉的Vue的双向绑定使用起来十分方便,因此研究了一下列表显示时分页的实现,这里我使用了bootstrap的样式,所以在页面中引用bootstrap的样式文件,后台提数据源使用.ne ...

  6. 【JavaScript&jQuery】返回顶部

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  7. js通过生成临时表单再删除的方式向后台提交数据(模拟ajax的post提交但还要跳转页面不返回数据)以及 struts向前台返回文件下载及防止中文乱码处理

    为了避免发送数据中有特殊字符,发送时用 encodeURIComponent 编码 (其实这个 if中是直接通过浏览器下载文件的方法,else是向后台传数据的方法) struts后台Action处理接 ...

  8. selenium测试 - open Firefox

    环境:Python2.7+selenium3+Firefox47   问题1: 在打开火狐浏览器时报错:‘geckodriver‘ executable needs to be in PATH fro ...

  9. Highcharts.js -纯javasctipt图表库初体验

    一.highcharts简介以及引入 highcharts作为免费提供给个人学习.个人网站和非商业用途使用的前端图表演示插件的确使用起来十分方便和轻便.在我最近完成一个需求的时候用到了它, 它的兼容性 ...

  10. linux 内存计算

    原文: http://www.open-open.com/lib/view/open1424325362577.html Linux中的Cache Memory 什么是Cache Memory(缓存内 ...