Mathematical#
formula.math
module#
Mathematical operations for the MRFM simulation.
- mrfmsim.formula.math.as_strided_x(dataset, window)[source]#
Function for adjusting the stride size in the x direction.
The operation is very fast and does not require extra memory because it only defines the stride size rather than creating a new array For a dataset with a shape of (6, 5, 4) with a window of 3 in the x direction, the resulting array shape is (4, 5, 4). The two new parameters are (4, 6, 5, 4), stride is (160, 160, 32, 8) if each element is 2 bytes For example, to determine the max value of a 3-dimensional array for every 3 elements in x direction:
dataset_strided = strided_axis0(dataset, 3) dataset_strided.max(axis = 1)
For more information, see as_strided and numpy arrays memory and strides.
- Parameters:
dataset (array) – the dataset target to determine max and min (or other running operations)
window (int) – the size of a sliding window for the dataset
- Returns:
strided dataset
- Return type:
ndarray
- mrfmsim.formula.math.slice_matrix(matrix, shape)[source]#
Slice numpy matrix.
The function only slices the matrix in the middle based on the shape. The resulting array should be a view of the original array, which provides memory and speed improvement.
- Parameters:
matrix (ndarray) – a numpy array.
shape (tuple) – sliced shape, has the same dimension as the matrix. The shape along the sliced axis should be the same oddity as the matrix.