The reduce_sum function of tensorflow learning summary

tensorflow integrates many mathematical functions based on statistics, similar to reduce_sum, reduce_mean, reduce_min, reduce_max, etc. According to the literal meaning, they are sum, average, maximum, minimum, etc.

reduce_sum() is the summation. Since the object of the summation is a tensor, it is summed along some dimensions of the tensor. reduction_indices refers to which dimensions of the tensor are summed. The following is an example to describe the specific operation of dimension summation:

Below is a 2*3*4 tensor.

[[[ 1 2 3 4]

[ 5 6 7 8]

[ 9 10 11 12]]

[[13 14 15 16]

[17 18 19 20]

[21 22 23 24]]]

If you calculate tf.reduce_sum(tensor, axis=0), axis=0 means that the sum is performed according to the first dimension, that is to say, the

[[ 1 2 3 4]

[ 5 6 7 8]

[ 9 10 11 12]

and

[[13 14 15 16]

[17 18 19 20]

[21 22 23 24]] is added, so the first dimension (that is, 2) is erased, and the tensor_ans obtained at the end of the summation is 3*4 (the previous tensor was 2*3*4). Obviously the elements of tensor_ans are 1+13; 2+14; 3+15...; 12+24. which is:

[[1+13 2+14 3+15 4+16]

[5+17 6+18 7+19 8+20]

[9+21 10+22 11+23 12+24]]。

By analogy, if axis=1, then the shape of the summation result is 2*4, that is:

[[ 1 + 5 + 9 2 + 6+10 3 + 7+11 4 + 8+12]

[13+17+21 14+18+22 15+19+23 16+20+24]]

If axis=2, then the shape of the summation result is 2*3, that is:

[[1+2+3+4 5+6+7+8 9+10+11+12]

[13+14+15+16 17+18+19+20 21+22+23+24]]  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324606266&siteId=291194637