Matrix (Matrix matrix) { if (getColumns() != matrix.getRows()) throw new IllegalArgumentException("columns mismatch rows"); int width = matrix.getColumns(); int height = getRows(); double[] result = new double[width * height]; for (int i = 0, h = 0; h < height; h++) { Vector row = getRow(h); for (int w = 0; w < width; w++, i++) { result[i] = row.multiply(matrix.getColumn(w)); } } return new Matrix(width, height, result); }