This is a pretty basic question but since you're new here let me get you started. Many functions in Mathematica are natively designed to work on vectors, arrays, and tensors. That means that such an operation is or at least may be directly analogous to the non-array form. Suppose you have:
a1 = RandomInteger[9, {5, 5}];
a2 = RandomInteger[9, {5, 5}];
a3 = RandomInteger[9, {5, 5}];
You then need merely:
(a1 + a2 + a3) / 3
Or:
Mean[{a1, a2, a3}]
Just as you would if a1
, a2
and a3
were individual numbers. This will be much faster than a manual procedural operation, unless you are going to compile that procedural code.
A sidebar
You could define all three arrays at once using:
{a1, a2, a3} = RandomInteger[9, {3, 5, 5}];
There is a subtle yet important difference however. This more concise form will unpack the packed integer array that is produced by RandomInteger
, resulting in slower numeric operations on those expressions.