TensorFlow之函数:reduce_mean() 来自于numpy.mean()

该博客详细对比了TensorFlow中的`tf.reduce_mean()`与numpy中的`np.mean()`函数。这两个函数用于计算张量或数组的平均值。`tf.reduce_mean()`在TensorFlow中用于沿着指定维度计算元素的平均值,而`np.mean()`则在numpy中执行相同操作。博客中包含函数的声明、参数说明、返回值以及示例代码,帮助理解两者之间的差异和用法。
摘要由CSDN通过智能技术生成

1. tf.reduce_mean()

1.1 函数声明
tf.reduce_mean(input_tensor, reduction_indices=None, keep_dims=False, name=None)
1.2 函数说明

Computes the mean of elements across dimensions of a tensor.

Reduces input_tensor along the dimensions given in reduction_indices. Unless keep_dims is true, the rank of the tensor is reduced by 1 for each entry in reduction_indices. If keep_dims is true, the reduced dimensions are retained with length 1.

If reduction_indices has no entries, all dimensions are reduced, and a tensor with a single element is returned.

1.3 参数说明

Args:

input_tensor: The tensor to reduce. Should have numeric type.
reduction_indices: The dimensions to reduce. If None (the default), reduces all dimensions.
keep_dims: If true, retains reduced dimensions with length 1.
name: A name for the operation (optional).
1.4 返回值

Returns:

The reduced tensor.

1.5 举例

For example:

# 'x' is [[1., 1.]
#         [2., 2.]]
tf.reduce_mean(x) ==> 1.5
tf.reduce_mean(x, 0) ==> [1.5, 1.5]
tf.reduce_mean(x, 1) ==> [1.,  2.]

2. np.mean()

2.1 函数声明
numpy.mean(a, axis=
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值