Learn Before
Code

Programmatic Tensor Mean

Because calculating the average is a frequent requirement in deep learning, frameworks provide dedicated functions for computing the mean, which operate analogously to their summation counterparts. These functions can reduce an entire tensor to a scalar or target specific axes. For instance, PyTorch, MXNet, and JAX use the .mean() method (e.g., A.mean() or A.mean(axis=0)), while TensorFlow utilizes the tf.reduce_mean() function to achieve the same result.

0

1

Updated 2026-05-02

Contributors are:

Who are from:

Tags

D2L

Dive into Deep Learning @ D2L