unshiftdata
The inverse function to shiftdata.
| Library |
|
Arguments
Examples
Rearranging the dimensions of the magic Square
Details
Let’s make shifts in the magic square 3×3 by rearranging the second dimension into the first column using the function shiftdata. Let’s return the matrix to its original position using the function unshiftdata.
Let’s set a magic square 3×3.
import EngeeDSP.Functions: shiftdata
import EngeeDSP.Functions: unshiftdata
x = [2 9 4; 7 5 3; 6 1 8]
3×3 Matrix{Int64}:
8 1 6
3 5 7
4 9 2
Let’s shift the matrix to work along the second dimension. Let’s return the permutation vector, the number of shifts, and the shifted matrix.
x, perm, nshifts = shiftdata(x, 2)
(x = [8 3 4; 1 5 9; 6 7 2], perm = (2, 1), nshifts = Any[])
Let’s restore the matrix to its original state.
y = unshiftdata(x, perm)
3×3 Matrix{Int64}:
8 1 6
3 5 7
4 9 2
Rearranging the array to work with the first non-single dimension
Details
Let’s define the data for the shift as a row vector.
import EngeeDSP.Functions: shiftdata
import EngeeDSP.Functions: unshiftdata
x = [1 2 3 4 5]
1×5 Matrix{Int64}:
1 2 3 4 5
To move the first data dimension, which is not the only element in the array, to the first column, we will not specify dim. Function shiftdata returns data in the form of a column vector, a vector of permutations, and the number of shifts.
x, perm, nshifts = shiftdata(x)
(x = [1, 2, 3, 4, 5], perm = Any[], nshifts = 1)
Restoring the data to its original state.
y = unshiftdata(x, perm, nshifts)
1×5 Matrix{Int64}:
1 2 3 4 5