tf.keras.ops.moments

Calculates the mean and variance of x.

The mean and variance are calculated by aggregating the contents of x across axes. If x is 1-D and axes = [0] this is just the mean and variance of a vector.

x Input tensor.
axes A list of axes which to compute mean and variance.
keepdims If this is set to True, the axes which are reduced are left in the result as dimensions with size one.
synchronized Only applicable with the TensorFlow backend. If True, synchronizes the global batch statistics (mean and variance) across all devices at each training step in a distributed training strategy. If False, each replica uses its own local batch statistics.

A tuple containing two tensors - mean and variance.

Example:

x = keras.ops.convert_to_tensor([0, 1, 2, 3, 100], dtype="float32")
keras.ops.moments(x, axes=[0])
(array(21.2, dtype=float32), array(1553.3601, dtype=float32))