2

Given some vector of numbers, I want to apply a different function to the vector and get a matrix of the results. Is there an idiomatic way of doing this in breeze?

import breeze.linalg._
val dv = DenseMatrix(0.0, 5.0, 6.0, 3.0, 7.0)
val someOpDef = Seq(2.0, 3.0)
val resultButWrongFormat = for (i <- someOpDef) yield dv - i
resultButWrongFormat.reduce(DenseMatrix.horzcat(_, _))

This produces a DenseMatrix, but it feels clunky vs matlab syntax.

import breeze.linalg._
dv: breeze.linalg.DenseMatrix[Double] =
0.0      5.0     6.0     3.0     7.0 

someOpDef: Seq[Double] = List(2.0, 3.0)

res0: breeze.linalg.DenseMatrix[Double] =
-2.0  -3.0
3.0   2.0
4.0   3.0
1.0   0.0
5.0   4.0
Krzysztof Atłasik
  • 21,985
  • 6
  • 54
  • 76
Simon
  • 323
  • 2
  • 15

0 Answers0