I'm coming from IDL, so I'm most used to for loops with explicit indicing. I have read about how python does things differently and that you should just be able to say
for thing in things:
What I can't figure out is if a I have a 4 dimensional array and I want to perform an operation in one dimension of the array, how do I save out the result in a 4 dimensional array and do it in the 'python' way.
I have a 4 dimensional array in time, altitude, latitude, longitude. I want to smooth it using a running mean window of N=9.
Here is the code that I am working with:
KMCM_T = g.variables['temperature'][:,:,:,:] #K
N = 9
T_bar_run = []
for idx, lon in enumerate(KMCM_lon):
for idy, lat in enumerate(KMCM_lat):
for idz, lev in enumerate(KMCM_levels):
T_bar_run[:][idz][idy][idx] = np.convolve(KMCM_T[:,idz,idy,idx], np.ones((N,))/N, mode='same')