TensorFlow reduce_sum

TensorFlow reduce_sum

flyfish

import numpy as np
import tensorflow as tf

x = np.array([[1,2,3],[4,5,6]])
sess = tf.Session()

sum0 = np.sum(x, axis=0)
sum1 = np.sum(x, axis=1)

sum2 = sess.run(tf.reduce_sum(x))
sum3 = sess.run(tf.reduce_sum(x, 0))
sum4 = sess.run(tf.reduce_sum(x, 1))
sum5 = sess.run(tf.reduce_sum(x, 1, keep_dims=True))
sum6 = sess.run(tf.reduce_sum(x, [0, 1]))


print (sum0)
print (sum1)
print (sum2)
print (sum3)
print (sum4)
print (sum5)
print (sum6)
sess.close()

TensorFlow reduce_sum_第1张图片

你可能感兴趣的:(Python)