3

I am a bit lost among all those available operators -- so is there easy way to insert a entire row/column (vector) into a matrix?

I started thinking about creating a vector, converting it to array, joining it with matrix converted into array, and creating new matrix based on such combined array, but it looks even uglier than it sounds.

greenoldman
  • 16,895
  • 26
  • 119
  • 185
  • 1
    Any reason you're still using scalala and not [breeze](https://github.com/scalanlp/breeze)? – dhg Sep 16 '12 at 18:25
  • 1
    @dhg, "still"? I just started using it few days ago ;-). I didn't even find a word about breeze up till now. I will take a look, thank you. The question still holds than (for breeze as well). – greenoldman Sep 16 '12 at 18:30

1 Answers1

5
val m = DenseMatrix((1, 4, 10, 13), (2, 5, 11, 14), (3, 6, 12, 15))

val v = DenseVector(7, 8, 9)

val m2 = DenseMatrix.zeros[Int](3, 5)
m2(::, 0 to 1) := m(::, 0 to 1)
m2(::, 2) := v
m2(::, 3 to 4) := m(::, 2 to 3)

You'll find more information about basic breeze functionality here.

dhg
  • 52,383
  • 8
  • 123
  • 144