chemotools.adaptation.functions.scale_by_factor#

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

Multiply every row of X by a scalar or array factor.

Useful for per-batch or per-sample intensity rescaling, e.g. correcting for integration time, path-length, or dilution differences.

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

  • factor (float or np.ndarray) –

    Scaling factor. Accepted shapes:

    • scalar float — multiplies every element.

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

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

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

Returns:

X_scaled – X * factor.

Return type:

np.ndarray of shape (n_samples, n_features)

Examples

>>> import numpy as np
>>> from chemotools.adaptation.functions import scale_by_factor
>>> X = np.array([[1.0, 2.0], [3.0, 4.0]])
>>> scale_by_factor(X, np.array([[2.0], [0.5]]))
array([[2. , 4. ],
       [1.5, 2. ]])