scalamatrixbreeze

Scala breeze.linalg Densematrix: unable to assign columns


I cannot assign a column via A(::,1) = DenseVector to a DenseMatrix A. Here is what I get in the repl:

scala> val A=DenseMatrix.vertcat(DenseVector(11,12).toDenseMatrix,DenseVector(21,22).toDenseMatrix)
A: breeze.linalg.DenseMatrix[Int] =
11  12
21  22

scala> A(::,1) = DenseVector(13,23)
<console>:14: error: type mismatch;
found   : collection.immutable.::.type
required: Int
   A(::,1) = DenseVector(13,23)
     ^

Scala version is 2.12, breeze version: 1.0. This is similar to this question where it is stated that this should work. The problem persists if A is declared as a var.


Solution

  • You're close...

    A(::,1) := DenseVector(13,23)
    

    https://github.com/scalanlp/breeze/wiki/Linear-Algebra-Cheat-Sheet