tf.reduce_sum(tf.square(output_vector),axis,keep_dims = True)在做什么?

时间:2019-03-16 00:16:47

标签: tensorflow

此功能在做什么我没明白。

<Form/>

此部分: tf.reduce_sum(tf.square(output_vector),axis,keep_dims = True)

1 个答案:

答案 0 :(得分:0)

让我们逐行看看:

X = np.array([[1,2,3],[4,5,6]])
squared = tf.square(X)
# Each element of the input vector will be put to the power of 2
# [[ 1  4  9]
#  [16 25 36]]
reduced_0_keepdims = tf.reduce_sum(squared, axis=0, keepdims=True)
# Elements will be summed on the specified axis and
# by setting keepdims=True the dimensions of the output tensor
# will remain the same
# [[17 29 45]]
reduced_1 = tf.reduce_sum(squared, axis=1)
# Elements will be summed on the specified axis and the tensor will be reduced
# [14 77]