matrixToVector

Parameters

Parameter label

I/O type

Data type

Mandatory parameter?

Default value

inputVec

input

matrix (2D numpy array

yes

N/A

mode

input

string ("diag"|"upperTriangular"|"lowerTriangular"|"stackToVector")

no

"diag"

diagOffset

input

scalar

no

0

stackOrientation

input

string ("rows"|"cols")

no

"rows"

outputVec

output

vector

N/A

N/A

Functionality

Module converts a 2D numpy array (matrix) into a 1D numpy array (vector).

If mode="diag", the main diagonal (diagOffset=0) or a side diagonal (diagOffset<>0) is stored as outputVec. Values of diagOffset smaller than zero refer to the side diagonals below the main diagonal.

If mode="upperTriangular", the upper triangular matrix is stacked row-wise into outputVec. Similarly, if mode="lowerTriangular", the lower triangular matrix is stacked row-wise into outputVec.

If mode="stackToVector", the matrix is stacked into outputVec row-wise (stackOrientation="rows") or column-wise (stackOrientation="cols").

Here are some examples:

inputVec = [np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])]
mode = "diag"
diagOffset = 0
...
outputVec = [1,6,11,16]
inputVec = [np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])]
mode = "diag"
diagOffset = 2
...
outputVec = [2,7,12]
inputVec = [np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])]
mode = "diag"
diagOffset = -1
...
outputVec = [5,10,15]
inputVec = [np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])]
mode = "upperTriangular"
diagOffset = 0
...
outputVec = [1,2,3,4,6,7,8,11,12,16]
inputVec = [np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])]
mode = "upperTriangular"
diagOffset = 1
...
outputVec = [2,3,4,7,8,12]
inputVec = [np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])]
mode = "upperTriangular"
diagOffset = 1
...
outputVec = [2,3,4,7,8,12]
inputVec = [np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])]
mode = "lowerTriangular"
diagOffset = 0
...
outputVec = [1,5,6,9,10,11,13,14,15,16]
inputVec = [np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])]
mode = "lowerTriangular"
diagOffset = -1
...
outputVec = [5,9,10,13,14,15]
inputVec = [np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])]
mode = "stackToVector"
stackOrientation = "rows"
...
outputVec = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
inputVec = [np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])]
mode = "stackToVector"
stackOrientation = "cols"
...
outputVec = 1,5,9,13,2,6,10,14,3,7,11,15,4,8,12,16]