Using Scalala, it was possible to perform elementary operations on a vector using a scalar operand. Let's say you have a vector of random numbers between 0 and 1, and you want to subtract each value from 1:
import breeze.linalg._ val x = DenseVector.rand(5) val y = 1d :- x
Unlike Scalala, Breeze cannot compile this approach. You can get around this by creating a vector of them, but it seems like there should be a better way.
val y = DenseVector.ones[Double](x.size) :- x
Another workaround would be to use the mapValues ββmethod, which is more readable:
val y = x mapValues { 1 - _ }
What is the right way to achieve this with Breeze?
source share