Numpy methods are going to beat python loops almost always, so I am going to skip your 1.

As for 2, in this particular case the following works:

a = np.array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11],
              [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]])
a = a.reshape(2, 3, 4)
>>> a
array([[[ 0,  1,  2,  3],
        [ 4,  5,  6,  7],
        [ 8,  9, 10, 11]],

       [[12, 13, 14, 15],
        [16, 17, 18, 19],
        [20, 21, 22, 23]]])
>>> np.mean(a, axis=1)
array([[  4.,   5.,   6.,   7.],
       [ 16.,  17.,  18.,  19.]])

The trick is in the reshape. For a general case where you want blocks of n columns, the following is an option

a = a.reshape((a.shape[0], -1, n))

Your concerns in 3 are mostly unwarranted. reshape returns a view of the original array, not a copy, so the conversion to 3D only requires altering the shape and strides attributes of the array, without having to copy any of the actual data.

EDIT To be sure that reshaping does not copy the array, but returns a view, do the reshape as

a.shape = a = a.reshape((a.shape[0], -1, n))

The example in the docs goes along the lines of:

>>> a = np.arange(12).reshape(3,4)
>>> b = a.T
>>> b.shape = (12,)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: incompatible shape for a non-contiguous array

And in general there are only problems if you have been doing transpose, rollaxis, swapaxes or the like on your array.

Answer from Jaime on Stack Overflow
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.average.html
numpy.average — NumPy v2.5 Manual
An array of weights associated with the values in a. Each value in a contributes to the average according to its associated weight. The array of weights must be the same shape as a if no axis is specified, otherwise the weights must have dimensions and shape consistent with a along the specified ...
🌐
GitHub
gist.github.com › shane5ul › 6289436ace018e6e9e79ee3489be2b8f
This program computes the block average of a potentially correlated timeseries "x", and provides error bounds for the estimated mean <x>. As input provide a vector or timeseries "x", and the largest block size. · GitHub
I think the following line in line 43 is not correct: blockVar[blockCtr] = np.var(obsProp)/(Nblock - 1) see https://numpy.org/doc/stable/reference/generated/numpy.var.html · the np.var already divides by the number of samples N=Nblocks, but when we want to use -1 , specify ddof=1 So the line becomes: blockVar[blockCtr] = np.var(obsProp, ddof=1) Copy link ·
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.block.html
numpy.block — NumPy v2.5 Manual
Blocks in the innermost lists are concatenated (see concatenate) along the last dimension (-1), then these are concatenated along the second-last dimension (-2), and so on until the outermost list is reached.
🌐
Stack Overflow
stackoverflow.com › questions › 78618965 › how-to-average-every-nxn-block-in-a-2d-numpy-array
python - How to average every NxN block in a 2d numpy array - Stack Overflow
I want to create a new (3, 2) array 2x2_means containing the mean of each 2x2 block inside array · So, 2x2_means[0, 0] would be the mean of array[:2, :2]: ... I want to be able to do this with much larger array shapes as well (e.g. averaging 25x25 blocks of elements over a 1000x1000 array)
🌐
SciPy Lecture Notes
scipy-lectures.org › advanced › image_processing › auto_examples › plot_block_mean.html
2.6.8.5. Plot the block mean of an image — Scipy lecture notes
2.6. Image manipulation and processing using Numpy and Scipy » · Collapse document to compact view · Edit Improve this page: Edit it on Github. Note · Click here to download the full example code · An example showing how to use broad-casting to plot the mean of blocks of an image.
🌐
SciPy
docs.scipy.org › doc › numpy-1.15.1 › reference › generated › numpy.average.html
numpy.average — NumPy v1.15 Manual
numpy.average(a, axis=None, weights=None, returned=False)[source]¶ · Compute the weighted average along the specified axis. See also · mean · ma.average · average for masked arrays – useful if your data contains “missing” values · Examples · >>> data = range(1,5) >>> data [1, 2, 3, 4] >>> np.average(data) 2.5 >>> np.average(range(1,11), weights=range(10,0,-1)) 4.0 ·
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › averaging-over-every-n-elements-of-a-numpy-array
Averaging over every N elements of a Numpy Array - GeeksforGeeks
July 23, 2025 - numpy.average() to calculate the average i.e the sum of all the numbers divided by the number of elements
🌐
Astropy
docs.astropy.org › en › stable › api › astropy.nddata.block_reduce.html
block_reduce — Astropy v7.1.1
The default is sum, which provides block summation (and conserves the data sum). ... The resampled data. Note the depending on the input func, the dtype of the output array may not match the input array. ... >>> import numpy as np >>> from astropy.nddata import block_reduce >>> data = np.arange(16).reshape(4, 4) >>> block_reduce(data, 2) array([[10, 18], [42, 50]])
🌐
w3resource
w3resource.com › numpy › manipulation › block.php
NumPy: numpy.block() function - w3resource
April 24, 2026 - Numpy Array manipulation: numpy.block() is stack arrays in sequence vertically (row wise).
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.average.html
numpy.average — NumPy v2.0 Manual
An array of weights associated with the values in a. Each value in a contributes to the average according to its associated weight. The array of weights must be the same shape as a if no axis is specified, otherwise the weights must have dimensions and shape consistent with a along the specified ...
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.average.html
numpy.average — NumPy v2.2 Manual
An array of weights associated with the values in a. Each value in a contributes to the average according to its associated weight. The array of weights must be the same shape as a if no axis is specified, otherwise the weights must have dimensions and shape consistent with a along the specified ...
🌐
Mdanalysis
mdanalysis.org › pages › errata
Paper Errata · MDAnalysis
def blocked(universe, nblocks, analyze): size = universe.trajectory.numframes/nblocks blocks = [] for block in xrange(nblocks): a = [] for ts in u.trajectory[block*size:(block+1)*size]: a.append(analyze(universe)) blocks.append(numpy.average(a)) blockaverage = numpy.average(blocks) blockstd ...
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.average.html
numpy.average — NumPy v2.3 Manual
An array of weights associated with the values in a. Each value in a contributes to the average according to its associated weight. The array of weights must be the same shape as a if no axis is specified, otherwise the weights must have dimensions and shape consistent with a along the specified ...