I am hard-coding a matrix with the values below:
val m = breeze.linalg.DenseMatrix((1, 4), (2, 5))
val v = breeze.linalg.DenseMatrix((7, 8), (3, 6))
I want to insert these values on the rows and columns by reading from lists.
I am hard-coding a matrix with the values below:
val m = breeze.linalg.DenseMatrix((1, 4), (2, 5))
val v = breeze.linalg.DenseMatrix((7, 8), (3, 6))
I want to insert these values on the rows and columns by reading from lists.
If you have a rows:Seq[Seq[Double]]
, where each entry in the outer ~eq is a row:
DenseMatrix(rows:_*)
If you know the matrix dimensions ahead of time, and you have DenseVectors for each row/column)
val dm = DenseMatrix.zeros[Double](rows, cols)
dm(::, c) := myColDenseVector
dm(r, ::) := myRowDenseVector.t
Alternatively, if you have a bunch of DenseVectors, you can say: DenseVector.horzcat(columns:_*)
This is what I found out:
val x = new DenseMatrix(2, 3, Array(11, 12, 13, 21, 22, 23))
which gives the matrix with 2 rows and 3 columns by slicing off the numbers 2 and 3 specified from the array.
The result is:
11 13 22
12 21 23