我正在学习tensorflow,我从tensorflow网站取得了以下代码。根据我的理解,axis = 0是行,axis = 1是列。
他们如何得到注释中提到的输出?根据我的想法,我已经在“##”旁边标出了输出。
import tensorflow as tf
x = tf.constant([[1, 1, 1], [1, 1, 1]])
tf.reduce_sum(x, 0) # [2, 2, 2] ## [3, 3]
tf.reduce_sum(x, 1) # [3, 3] ##[2, 2, 2]
tf.reduce_sum(x, [0, 1]) # 6 ## Didn't understand at all.
tf.reduce_sum(x)
与tf.reduce_sum(x, [0, 1])
也是等价的。换句话说,如果您不指定要缩减的维度,它将沿着所有维度进行缩减。 - Vivek Subramanian