You have plenty of redundant operations here:
The equivalent code is (where a
is a matrix and b
is a list of 3-vectors):
Abs[MatrixAMap[Norm[#]^2 &, a . VectorB]^2b];
I have:
n = 500;
a = RandomReal[1, {1500n, 1500n}];
b = RandomReal[1, 1500];{n, 3}];
oneDimArray =
Table[(Norm[Sum[a[[i, j]] b[[j]], {j, 1500n}]])^2, {i,
1500 n}]; // AbsoluteTiming
(* {246.907265618, Null} *)
Abs[aoneDimArrayMap = Map[Norm[#]^2 &, a.b]^2;b]; // AbsoluteTiming
(* {0.000943871000621823, Null} *)
oneDimArray == oneDimArrayMap
(* True *)
Thus, using Dot
almost 300070000 times faster than manual loops.