Compute the weighted average along the specified axis.
View aliases
Main aliases
tf.keras.ops.average(
x, axis=None, weights=None
)
Returns | |
---|---|
Return the average along the specified axis. |
Examples:
data = keras.ops.arange(1, 5)
data
array([1, 2, 3, 4], dtype=int32)
keras.ops.average(data)
array(2.5, dtype=float32)
keras.ops.average(
keras.ops.arange(1, 11),
weights=keras.ops.arange(10, 0, -1)
)
array(4., dtype=float32)
data = keras.ops.arange(6).reshape((3, 2))
data
array([[0, 1],
[2, 3],
[4, 5]], dtype=int32)
keras.ops.average(
data,
axis=1,
weights=keras.ops.array([1./4, 3./4])
)
array([0.75, 2.75, 4.75], dtype=float32)
keras.ops.average(
data,
weights=keras.ops.array([1./4, 3./4])
)
Traceback (most recent call last):
ValueError: Axis must be specified when shapes of a and weights differ.