自己開發了一個股票智能分析軟件,功能很強大,需要的點擊下面的鏈接獲取:
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求最小值,參數含義相同