Broadcasted vector divided by matrix?

18 views
Skip to first unread message

marko

unread,
Jan 22, 2018, 12:49:24 PM1/22/18
to Scala Breeze
Hi,

What's the best way to do divide a vector by matrix similar to what
NumPy would do with np.divide(y, a)?

val y: DenseVector[Double] = ???
val a: DenseMatrix[Double] = ???

One solution I came up with is to first do an element-wise inverse
on matrix 'a' and then a broadcasted multiply between 'y' and 'a', but is there a better way to do this?

marko

David Hall

unread,
Jan 22, 2018, 3:22:24 PM1/22/18
to scala-...@googlegroups.com
Looks like broadcasts can by the RHS yet, so you have the right idea. I'll try to fix that before 1.0

val aRecip = 1.0 /:/ a
y *:* aRecip

in one line:

y *:* (1.0 /:/ a).apply(::, *) 

-- David

--
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+unsubscribe@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/msgid/scala-breeze/5db5ab19-da70-46f1-863a-7c6ad6483538%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages