TensorFlow (未完待续……)

API手册:https://docs.w3cub.com/tensorflow~python/

 

1. tf.reduce_xxxx

- tf.reduce_sum() #压缩对所有元素求和,用于降维

- tf.reduce_mean() #压缩对所有元素求平均值

- tf.reduce_logsumexp() #压缩对所有元素求log(sum(exp(x)))

- tf.reduce_max() #压缩对所有元素求最大值

- tf.reduce_min() #压缩对所有元素求最小值

- tf.reduce_prod() #压缩对所有元素求积

- tf.reduce_join() #压缩对所有字符串元素求拼接

- tf.reduce_all() #压缩对所有逻辑元素求与

- tf.reduce_any() #压缩对所有逻辑元素求或

import tensorflow as tf

 

x = tf.constant([[1,1,1],[1,1,1]])
print(tf.reduce_sum(x)) 

# 求和:tf.Tensor(6, shape=(), dtype=int32)


print(tf.reduce_sum(x, 0)) 

# 按列求和:tf.Tensor([2 2 2], shape=(3,), dtype=int32)


print(tf.reduce_sum(x, 1)) 

# 按行求和:tf.Tensor([3 3], shape=(2,), dtype=int32)


print(tf.reduce_sum(x, 1, keepdims=True)) 

# 按照行的维度进行求和: tf.Tensor([[3],[3]], shape=(2, 1), dtype=int32)


print(tf.reduce_sum(x, [0, 1])) 

# 按照行列求和:tf.Tensor(6, shape=(), dtype=int32)

See details at: https://docs.w3cub.com/tensorflow~python/tf/reduce_sum/

发布了4 篇原创文章 · 获赞 0 · 访问量 80

猜你喜欢

转载自blog.csdn.net/scorpioji/article/details/104162973