当前位置:网站首页>tf.reduce_mean() and tf.reduce_sum()

tf.reduce_mean() and tf.reduce_sum()

2022-08-11 07:51:00 phac123

Introduction

TF.reduce_mean() and tf.reduce_sum() are often used in TF to average and sum the specified dimensions of the specified tensor respectively.

# Calculates the mean of a tensor along the specified dimensiontf.reduce_mean (tensor name, axis=operation axis)# Calculate the sum of the tensor along the specified dimensiontf.reduce_sum (tensor name, axis=operation axis)

Code

import tensorflow as tfx = tf.constant([[1, 2, 3], [2, 2, 3]])print("x: ", x)print("mean of x: ", tf.reduce_mean(x))print("mean of x: ", tf.reduce_mean(x, axis = 0))print("mean of x: ", tf.reduce_mean(x, axis = 1))print("mean of x: ", tf.reduce_sum(x))print("sum of x: ", tf.reduce_sum(x, axis = 0))print("sum of x: ", tf.reduce_sum(x, axis = 1))

insert image description here

Which axis is specified, turn that dimension into 1 row/column/…

原网站

版权声明
本文为[phac123]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110645028126.html