shift()#

shift(states: ndarray, shift_by: ndarray = None)[source]#

Shift the columns of a snapshot matrix by a vector.

Parameters
states(n, k) ndarray

Matrix of k snapshots. Each column is a single snapshot.

shift_by(n,) ndarray

Vector that is the same size as a single snapshot. If None (default), set to the mean of the columns of states.

Returns
states_shifted(n, k) ndarray

Shifted state matrix, i.e., states_shifted[:, j] = states[:, j] - shift_by.

shift_by(n,) ndarray

Shift factor, returned only if shift_by=None. Since this is a one-dimensional array, it must be reshaped to be applied to a matrix, for example, states_shifted = states - shift_by.reshape(-1, 1).

Examples

>>> import opinf
# Shift Q by its mean, then shift Y by the same mean.
>>> Q_shifted, qbar = opinf.pre.shift(Q)
>>> Y_shifted = opinf.pre.shift(Y, qbar)
# Shift Q by its mean, then undo the transformation by an inverse shift.
>>> Q_shifted, qbar = opinf.pre.shift(Q)
>>> Q_again = opinf.pre.shift(Q_shifted, -qbar)