I have a function to calculate the moving average of numpy arrays imported from a file. This function works fine, but I was wondering if anyone knows a quicker method, using one of numpy methods to have the same outcome??
Data:
b = [[1, 2, 3],
[2, 3, 4],
[3, 4, 5],
[6, 7, 8],
[4, 5, 6]]
def mod_movAvg(arr):
rowNum, colNum = arr.shape
res = np.zeros((rowNum - 1, colNum))
for col in range(colNum):
for row in range(rowNum - 1):
res[row][col] = 0.5*(arr[row][col] + arr[row+1][col])
return res
output:
[[1.5 2.5 3.5]
[2.5 3.5 4.5]
[4.5 5.5 6.5]
[5. 6. 7. ]]