Re: [scala-breeze] Vector(range) operations

106 views
Skip to first unread message

David Hall

unread,
May 10, 2013, 12:49:43 PM5/10/13
to scala-...@googlegroups.com
no, that syntax is for slicing an existing vector... What you've done is created a DenseVector with a range as its elements. I.e. DenseVector[NumericRange[Double]]

I guess I just didn't add an equivalent method yet.

new breeze.linalg.DenseVector( (0.0 to 40.0 by 1.0).toArray) will work in the meantime.






On Fri, May 10, 2013 at 7:26 AM, Allan Brighton <alla...@gmail.com> wrote:
Hi,

I'm trying to port some Scalala code that created a Vector with a range of double values:

  Vector.range(0, 40)

In Breeze that seems to be:

   DenseVector(0.0 to 40.0 by 1.0)

But the vector that is created doesn't work with :* or :+

<console>:15: error: could not find implicit value for parameter op: breeze.linalg.operators.BinaryOp[breeze.linalg.DenseVector[scala.collection.immutable.NumericRange[Double]],Double,breeze.linalg.operators.OpMulScalar,That]
              DenseVector(0.0 to 40.0 by 1.0) :* 2.0

(I know I could put the "2.0" after "by" in this case)

What is the correct way to create a vector(1.0, 2.0, 3.0, ...) and then be able to do math on it?

Thanks,
Allan

--
You received this message because you are subscribed to the Google Groups "Scala Breeze" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-breeze...@googlegroups.com.
To post to this group, send email to scala-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/scala-breeze/-/sNerGPOAT40J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

David Hall

unread,
May 10, 2013, 12:51:55 PM5/10/13
to scala-...@googlegroups.com
There's also linspace.

scala> breeze.linalg.linspace(0.0,39.0,40)
res8: breeze.linalg.DenseVector[Double] = DenseVector(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0)



Allan Brighton

unread,
May 10, 2013, 2:28:59 PM5/10/13
to scala-...@googlegroups.com
Thanks, I realized that after I posted.

I was able to use this, which also works:

  DenseVector.tabulate(40)(_ * 1.0)

Not sure if one way is more efficient than the other.
Reply all
Reply to author
Forward
0 new messages