# to SUM tensor with array

Posted 9 years ago
5341 Views
|
2 Replies
|
1 Total Likes
|
 Hi, I have B = {a, b} and geom1Q = {{{0., -0.0975248}, {0., -0.666667}, {0.,-0.75}, {0., -0.833333}, {0., -0.916667}, {0., -1.}}, {{0., -0.0995336}, {0., -0.199067}} }I'd sum automatically B[[1]] with geom1Q[[1,All,2]] and B[[2]] with geom1Q[[2,All,2]] to have QQ = {{{0., -0.0975248+a}, {0., -0.666667+a}, {0.,-0.75+a}, {0., -0.833333+a}, {0., -0.916667+a}, {0., -1+a.}}, {{0., -0.0995336+b}, {0., -0.199067+b}} }So I have written this QQ = Table[Map[# + B[[i]] &, geom1Q[[i,All]] ] , {i, 1, Length[B]}]but my result is QQ = {{{0.+a, -0.0975248+a}, {0.+a, -0.666667+a}, {0.+a,-0.75+a}, {0.+a, -0.833333+a}, {0.+a, -0.916667+a}, {0.+a, -1+a.}}, {{0.+b, -0.0995336+b}, {0.+b, -0.199067+b}} }I need your help. Thank you Margherita
2 Replies
Sort By:
Posted 9 years ago
 Thank you
Posted 9 years ago
 Not particularly elegant, but gives the result: MapThread[Transpose[{#1, #2}] &, {geom1Q[[All, All, 1]], geom1Q[[All, All, 2]] + B}] Cheers,M.