tf.reduce_sum 语法

  1 #coding=utf8
  2 import tensorflow as tf
  3 import numpy as np
  4
  5 tf.compat.v1.disable_eager_execution()
  6
  7 x = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]) # shape = 2*2*3
  8 x_p = tf.compat.v1.placeholder(dtype=tf.int32, shape=[None, None, None], name='input')
  9
 10 #y =  tf.reduce_sum(x_p, 0) #修改这里
 11 #y =  tf.reduce_sum(x_p, 1) #修改这里
 12 y =  tf.reduce_sum(x_p, 2) #修改这里
 13
 14
 15 with tf.compat.v1.Session() as sess:
 16     y = sess.run(y, feed_dict={x_p: x})
 17     print(y)
tf.reduce_sum(x_p, 0):
[[ 8 10 12]
 [14 16 18]]
y =  tf.reduce_sum(x_p, 1)
[[ 5  7  9]
 [17 19 21]]
tf.reduce_sum(x_p, 2)
[[ 6 15]
 [24 33]]

 

你可能感兴趣的:(tf.reduce_sum 语法)