計算張量維度上元素的平均值。
用法
tf.compat.v1.reduce_mean(
input_tensor, axis=None, keepdims=None, name=None, reduction_indices=None,
keep_dims=None
)
參數
-
input_tensor
要減少的張量。應該是數字類型。 -
axis
要減小的尺寸。如果None
(默認),減少所有維度。必須在[-rank(input_tensor), rank(input_tensor))
範圍內。 -
keepdims
如果為真,則保留長度為 1 的縮減維度。 -
name
操作的名稱(可選)。 -
reduction_indices
軸的舊(不推薦)名稱。 -
keep_dims
keepdims
的已棄用別名。
返回
- 減少的張量。
通過計算 axis
中各個維度上元素的平均值,沿 axis
中給出的維度減少 input_tensor
。除非 keepdims
為真,否則對於 axis
中的每個條目,張量的等級都會減少 1,這必須是唯一的。如果keepdims
為真,則保留縮減的維度,長度為 1。
如果axis
為None,則所有維度都會減少,並返回具有單個元素的張量。
例如:
x = tf.constant([[1., 1.], [2., 2.]])
tf.reduce_mean(x)
<tf.Tensor:shape=(), dtype=float32, numpy=1.5>
tf.reduce_mean(x, 0)
<tf.Tensor:shape=(2,), dtype=float32, numpy=array([1.5, 1.5], dtype=float32)>
tf.reduce_mean(x, 1)
<tf.Tensor:shape=(2,), dtype=float32, numpy=array([1., 2.], dtype=float32)>
numpy 兼容性
相當於 np.mean
請注意np.mean
有一個dtype
參數,可用於指定輸出類型。默認情況下這是 dtype=float64
。另一方麵,tf.reduce_mean
具有來自 input_tensor
的激進類型推斷,例如:
x = tf.constant([1, 0, 1, 0])
tf.reduce_mean(x)
<tf.Tensor:shape=(), dtype=int32, numpy=0>
y = tf.constant([1., 0., 1., 0.])
tf.reduce_mean(y)
<tf.Tensor:shape=(), dtype=float32, numpy=0.5>
相關用法
- Python tf.compat.v1.reduce_max用法及代碼示例
- Python tf.compat.v1.reduce_min用法及代碼示例
- Python tf.compat.v1.reduce_sum用法及代碼示例
- Python tf.compat.v1.reduce_any用法及代碼示例
- Python tf.compat.v1.reduce_all用法及代碼示例
- Python tf.compat.v1.reduce_join用法及代碼示例
- Python tf.compat.v1.reduce_prod用法及代碼示例
- Python tf.compat.v1.reduce_logsumexp用法及代碼示例
- Python tf.compat.v1.reverse_sequence用法及代碼示例
- Python tf.compat.v1.random.stateless_multinomial用法及代碼示例
- Python tf.compat.v1.random_uniform_initializer.from_config用法及代碼示例
- Python tf.compat.v1.ragged.constant_value用法及代碼示例
- Python tf.compat.v1.random_normal_initializer用法及代碼示例
- Python tf.compat.v1.random_normal_initializer.from_config用法及代碼示例
- Python tf.compat.v1.random_poisson用法及代碼示例
- Python tf.compat.v1.random_uniform_initializer用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.reduce_mean。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。