关于reduce_sum的维度问题也容易让人迷惑,特找来好用的图示,一看即懂:
为了加深影响,给出简单code
import numpy as np
import tensorflow as tf
inputs = [[1,0,2],[3,2,4]]
inputs = np.array(inputs)
A = tf.sign(inputs)
B = tf.reduce_sum(A, reduction_indices=1)
with tf.Session() as sess:
print(sess.run(A))
print(sess.run(B))
执行结果如下: