Java Utililty Methods Matrix to Vector

List of utility methods to do Matrix to Vector

Description

The list of methods to do Matrix to Vector are organized into topic(s).

Method

double[]matrix2Vector(double[][] m)
matrix Vector
double[] v = new double[m.length];
for (int i = 0; i < v.length; i++) {
    v[i] = m[i][0];
return v;
int[]matrix2vector(int[][] matrix)
matrixvector
if (matrix == null || matrix.length <= 0 || matrix[0].length <= 0) {
    return null;
int[] vector = new int[matrix.length * matrix[0].length];
int index = 0;
for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < matrix[0].length; j++, index++) {
        vector[index] = matrix[i][j];
...
voidmatrixToVectorArray(int M, int N, float[][] a, float[] b)
Converts a 2D array into a 1D array leaving the result in b .
if (b.length == 0 || a.length == 0 || a[0].length == 0 || b.length != (M * N) || a.length != M
        || a[0].length != N) {
    throw new IllegalArgumentException(
            "The number of data points in both arrays must be equal and different from zero.");
for (int i = 0; i < M; i++) {
    System.arraycopy(a[i], 0, b, N * i, N);
voidmatrixToVectorArray(int M, int N, float[][] a, float[] b)
Converts a 2D array into a 1D array leaving the result in b .
checkDimension(a);
if (a.length != M || a[0].length != N || b.length == 0 || b.length != (M * N)) {
    throw new IllegalArgumentException(
            "The number of data points in both arrays must be equal and different from zero.");
for (int i = 0; i < M; i++) {
    System.arraycopy(a[i], 0, b, N * i, N);
double[]matrixVector(double[][] w, double[] v)
matrix Vector
int w1 = w.length;
int w2 = w[0].length;
int v1 = v.length;
if (w2 != v1) {
    System.out.println("Matrix dimensions do not agree...");
    System.exit(-1);
double[] result = new double[w1];
...
voidmatrixVectorProductVDw(final double[][] V, final double[] d, final double[] w, final double[] a, int l1, int l2)
Multiplies the matrix V (l1-by-l2) with diagonal matrix D (l2-by-l2) and then with vector w (l2).
assert hasShape(V, l1, l2);
assert d != null;
assert w != null;
assert a != null;
assert d.length >= l2;
assert w.length >= l2;
assert a.length >= l1;
for (int i = 0; i < l1; i++) {
...