reduce_sum(arg1,arg2),降维,求和.
arg1为输入的数据,arg2参数,按行求和还是按列求和,或者求总和.
arg2:axis=0,or 1,or[0,1] / keepdims=True
- axis=0 按列求和 axis=1 按行求和 axis=[0 1] 求总和
>>>x=[[3. 0. 3.]
[2. 3. 0.]
[0. 5. 3.]]
>>>sess.run( tf.reduce_sum(x,axis=0))
array([5., 8., 6.])
>>> sess.run( tf.reduce_sum(x,axis=1))
array([6., 5., 8.])
>>> sess.run( tf.reduce_sum(x,axis=[0,1]))
19.0
- keepdims=True,保持维度不变,但并不是行列数不变哦.
a= tf.reduce_sum(x,axis=0,keepdims = True)
>>> sess.run(a)
array([[5., 8., 6.]])
>>> print a.shape
(1, 3)
>>> b= tf.reduce_sum(x,axis=0)
>>> print b.shape
(3,)
>>> c= tf.reduce_sum(x,axis=[0,1],keepdims = True)
>>> sess.run(c)
array([[19.]])
>>> print c.shape
(1, 1)
>>> d= tf.reduce_sum(x,axis=[0,1])
>>> sess.run(d)
19.0
>>> print d.shape
()
tf.square(
x,
name=None
),计算x中元素的平方,返回值维度与x相同.
tf.math.squared_difference(
x,
y,
name=None),x y 维度需一致,计算(x-y)中元素的平方,返回值维度与x相同
>>> a =np.array([1,2,3])
>>> b =np.array([2,2,6])
>>> c=tf.squared_difference(a,b)
>>> sess.run(c)
array([1, 0, 9])
>>> d=tf.square(a)
>>> sess.run(d)
array([1, 4, 9])