I have 2 scala array and I would like to multiply them.
val x = Array(Array(1,2),Array(3,4),Array(5,6),Array(7,8),Array(9,10),Array(11,12),Array(13,14),Array(15,16),Array(17,18),Array(19,20),Array(21,22))
val y = Array(2, 5, 9)
I wish to get a Array.ofDim[Int](3, 2)
like
val z = Array(Array(1*2 + 3 *2 + 5*2 + 7*2... 2*2 + 4*2 + 6*2 + 8*2...,),Array(1*5 + 3*5 + 5*5 + 7*5... 2*5 + 4*5 + 6*5 + 8*5...,),Array(1*9 + 3 *9 + 5*9 + 7*9... 2*9 + 4*9 + 6*9 + 8*9...,)
I tried to use x.transpose
, then zip y
to do.
But it was something wrong.
How can I do that?
Sorry, my code is
x.transpose.map(_.sum) zip y map {case(a, b) => a * b }