zoukankan      html  css  js  c++  java
  • 3.5.2 reduce_sum、reduce_mean、reduce_max、reducemin函数详解

    自己开发了一个股票智能分析软件,功能很强大,需要的点击下面的链接获取:

    https://www.cnblogs.com/bclshuai/p/11380657.html

    1.1.1         reduce_sum、reduce_mean、reduce_max、reducemin函数介绍

    reduce_sum函数是用来求多维tensor的元素之和的方法,reduce是降维的意思,sum是求和的意思。其定义如下:

    reduce_sum(input_tensor, axis=None, keepdims=False, name=None)

    input_tensor:输入求和的张量

    axis:降维的维度,比如2行3列的矩阵,维度是(0,1)0表示行,1表示列。axis等于0时,2行3列变成1行3列;axis=1时,2行3列默认变为1行两列,只有在keepdims ,才是2行1列。

    keepdims:是否保持维度,如果为True,axis=1时,2行3列变为2行1列

    实例

    import tensorflow as tf
    import numpy as np
    x = tf.constant([[1, 1, 1], [1, 1, 1]])
    print(x)
    y1=tf.reduce_sum(x);
    print(y1)#不指定axis时,等于所有元素相加1+1+1+1+1+1+1=6
    y2=tf.reduce_sum(x,0)
    print(y2)#指定按行降维,变成一行3列,每列元素相加[2,2,2]
    y3=tf.reduce_sum(x,1)
    print(y3)#指定按列降维,每行元素相加,因为keepdims默认为false,输出1行2列[3,3]
    y4=tf.reduce_sum(x,1,True)
    print(y4)#指定按列降维,每行元素相加,同时保持维度,输出2行1列[[3],[3]]

    输出

    tf.Tensor(

    [[1 1 1]

     [1 1 1]], shape=(2, 3), dtype=int32)

    tf.Tensor(6, shape=(), dtype=int32)

    tf.Tensor([2 2 2], shape=(3,), dtype=int32)

    tf.Tensor([3 3], shape=(2,), dtype=int32)

    tf.Tensor(

    [[3]

     [3]], shape=(2, 1), dtype=int32)

    同理reduce_mean是求平均值,参数含义相同

    reduce_mean(input_tensor, axis=None, keepdims=False, name=None)

    reduce_max求最大值,参数含义相同

    reduce_max(input_tensor, axis=None, keepdims=False, name=None):

    reduce_min求最小值,参数含义相同

  • 相关阅读:
    VS中,如何将存在于解决方案里,但是没有显示出来的文件(或文件夹)显示到项目中。
    (转)分布式系统编程,你到哪一级了?
    领域驱动架构学习总结
    Java多线程总结
    MySQL更新优化
    MySQL查询优化
    MySQL索引
    MySQL优化
    MySQL联接操作
    MySQL架构
  • 原文地址:https://www.cnblogs.com/bclshuai/p/14252654.html
Copyright © 2011-2022 走看看