I have a very large masked NumPy array (originalArray
) with many rows and two columns. I want take the average of every two rows in originalArray
and build a newArray
in which each row is the average of two rows in originalArray
(so newArray
has half as many rows as originalArray
). This should be a simple thing to do, but the script below is EXTREMELY slow. Any advice from the community would be greatly appreciated.
newList = []
for i in range(0, originalArray.shape[0], 2):
r = originalArray[i:i+2,:].mean(axis=0)
newList.append(r)
newArray = np.asarray(newList)
There must be a more elegant way of doing this. Many thanks!