flatten_features

flatten_features(arr: ndarray, obs_axs: int = -2) ndarray[source][source]

Flatten features in an array.

This function swaps the first axis with the observation axis and reshapes the array to flatten all dimensions except the first one.

Parameters:
  • arr (np.ndarray) – The input array to flatten.

  • obs_axs (int, optional) – The axis containing observations, by default -2.

Returns:

The flattened array with shape (n_observations, n_features).

Return type:

np.ndarray

Examples

>>> import numpy as np
>>> np.random.seed(0)
>>> arr = np.random.rand(4, 3, 2)
>>> flatten_features(arr, obs_axs=-2)
array([[0.5488135 , 0.71518937, 0.43758721, 0.891773  , 0.56804456,
        0.92559664, 0.77815675, 0.87001215],
       [0.60276338, 0.54488318, 0.96366276, 0.38344152, 0.07103606,
        0.0871293 , 0.97861834, 0.79915856],
       [0.4236548 , 0.64589411, 0.79172504, 0.52889492, 0.0202184 ,
        0.83261985, 0.46147936, 0.78052918]])