Skip to content

Mean Function

The mean function computes the mean of a signal. Mean is often used as a summary statistic for a signal. Using the SlidingWindow abstraction, the mean can be computed over a sliding window of the signal to be produce a set of features that can be used for a downstream task.

mean_tf(x, where=lambda : not np.isnan(x))

Compute the mean of the values in x where where is True.

Parameters:

Name Type Description Default
x ndarray

The array to compute the mean of.

required
where Callable[[Union[int, float, int_, float_]], Union[bool, bool_]]

A function that takes a value and returns True or False. Default is lambda x: not np.isnan(x) i.e. a measurement is valid if it is not a NaN value.

lambda : not numpy.isnan(x)

Returns:

Type Description
Union[float, float_]

The mean of the values in x where where is True.

Examples

import numpy as np
import autonfeat as aft
import autonfeat.functional as F

# Random data
n_samples = 100
x = np.random.rand(n_samples)

# Create sliding window
ws = 10
ss = 10
window = aft.SlidingWindow(window_size=ws, step_size=ss)

# Get featurizer
featurizer = window.use(F.mean)

# Get features
features = featurizer(x)

# Print features
print(features)

If you enjoy using AutonFeat, please consider starring the repository ⭐️.