Outer Addition?

27 views
Skip to first unread message

Max

unread,
Sep 1, 2015, 7:40:28 PM9/1/15
to Scala Breeze
Hi,
I'm attempting to translate some numpy code into breeze code (I'm proficient in neither) and I'm currently struggling to replicate the broadcasting behaviour of adding a vector with a 1d array in numpy.
In numpy if I have a vector of shape (3,) and a (3,1) array and I use the + operator, I end up with a 3x3 array apparently due to its implicit broadcasting behaviour.

But does Breeze support this kind of broadcasting? I've been playing around trying to get the same kind of behaviour, but I think something is lacking.

Thanks for any help,
Max.

David Hall

unread,
Sep 1, 2015, 7:45:22 PM9/1/15
to scala-...@googlegroups.com
yeah, breeze broadcasting doesn't like that (it should be a(::, *) + a(*, ::))

But you can always do: val mat = DenseMatrix.tabulate(3,3)((i,j) => a1(i) + a2(j)) or whatever

--
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/msgid/scala-breeze/17202c11-f9f7-4360-9f47-40e67feb6a17%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Max

unread,
Sep 2, 2015, 4:26:09 AM9/2/15
to Scala Breeze
Awesome - thanks David.
Reply all
Reply to author
Forward
0 new messages