chemotools.adaptation.functions.add_offset#

chemotools.adaptation.functions.add_offset(X: ndarray, offset: float | ndarray) → ndarray[source]#

Add a baseline offset to every row of X.

Useful for correcting instrument drift, dark-current baselines, or additive scatter effects that have been measured externally.

Parameters:
  • X (np.ndarray of shape (n_samples, n_features)) – Input spectra.

  • offset (float or np.ndarray) –

    Offset to add. Accepted shapes:

    • scalar float — added to every element.

    • (n_samples, 1) — per-sample scalar offset.

    • (1, n_features) — per-feature offset shared across samples.

    • (n_samples, n_features) — per-sample full spectrum.

    1-D inputs are rejected; use .reshape(-1, 1) for per-sample or .reshape(1, -1) for per-feature.

Returns:

X_shifted – X + offset.

Return type:

np.ndarray of shape (n_samples, n_features)

Examples

>>> import numpy as np
>>> from chemotools.adaptation.functions import add_offset
>>> X = np.array([[1.0, 2.0, 3.0]])
>>> add_offset(X, np.array([[0.1, 0.2, 0.3]]))
array([[1.1, 2.2, 3.3]])