tensorflow学习
求期望值:tf.math.reduce_mean(
input_tensor, The tensor to reduce. Should have numeric type.
输入tensor
axis=None, The dimensions to reduce. If None (the default),
reduces all dimensions. Must be in the range [-
rank(input_tensor),rank(input_tensor)).
默认为None,所有的行列数据取平均。
从最外层区分 ,0指最外层,1:第二层…
例1:
[ [1,2], [3,4] ], axis=0: ( [1, 2] + [3, 4])/2 = [2, 3], axis = 1: [ [(1+2)/2], [(3+4)/2]
例2:
X =[ axis = 0
[ axis = 1
[ axis = 2
[ 1, 2 ], axis =3
[ 3, 4 ]
] ,
[ [ 5, 6 ],
[ 7, 8 ]
]
],
[
[
[8, 7 ],
[6, 5 ]
] ,
[ [ 4, 3 ],
[ 2, 1 ]
]
]
]
# axis = 0 [[[4,5,4.5],[4.5,4,5]],[[4.5,4.5],[4.5,4.5]]] shape(2,2,2)
# axis = 1 [[[3,4],[5,6]], [[6,5][4,3]]] avg([1,2] [5,6]) avg([3,4], [7,8]) , avg([8,7],[4,3]), avg([6,5],[2,1])
# axis = 2 [[[2,3],[6,7]],[[7,6][3,2]]] avg(1,3) (2,4) (5,7) (6,8) avg(8,6) (7,5) (4,2)(3,1)
# axis = 3 [[[1.5,3.5][5.5,7.5]],[[7.5,5.5][3.5,1.5]]] avg(1,2)(3,4)(5,6)(7,8) avg(7,8)(6,5)(4,3)(2,1)
keepdims=False, If true, retains reduced dimensions with length 1
name=None A name for the operation (optional).
)