Ein Neuling hier.Scala: Iteration 2d Array zu tun
val arr_one = Array(Array(1, 2), Array(3, 4), Array(5, 6),Array(x, y)..and so on)
val arr_two = Array(Array(2,3), Array(4, 5), Array(6, 7))
var tempArr = ArrayBuffer[Double]()
Ich möchte arr_one und arr_two multiplizieren. zum Beispiel
Iteration1: Array(3*2+4*3, 3*4 +4*5, 3*6+4*7)
assign
Iteration3 tempArr: Array(1*2+2*3, 1*4 +2*5, 1*6+2*7)
assign
Iteration2 tempArr Array(5*2+6*3, 5*4 +6*5, 5*6+6*7)
assign
ich, dass
val x = Array(1, 2) ; val y = Array(Array(2,3), Array(4, 5), Array(6, 7))
Ich kann, wenn
wusste tempArr verwendeny map {x zip _ map{case(a, b) => a * b} sum}
Aber wenn x wie arr_one Form, ich weiß nicht, wie man for loop or something else
verwendet, um das zu tun.
Ich habe wirklich auf Idee.
Wie kann ich das in scala tun?
Wirklich danke.
Was zwischen Iterationen zu Ihrem tempArr passiert? Benutzt du es innerhalb der Iteration oder kombinierst du es irgendwie mit dem vorherigen Wert von tempArr? – Mifeet