I have 3 arrays of the same dimension alt = np.array(186 values)
, sza = np.array(186 values)
and per = np.array(186 values)
. I need to make a grid with the per
values over (alt,sza)
.
I have tried the following code and it is time-consuming process. Can anyone suggest improvisation for the code.
JavaScript
x
16
16
1
als = np.arange(150,510,5)
2
szde = np.arange(90,190,5)
3
4
val2 = []
5
for h in range(len(als)-1):
6
val1=[]
7
for h1 in range(len(szde)-1):
8
val=[]
9
for h2 in range(len(per)):
10
if ((als[h+1] >= alt[h2] >= als[h]) and (szde[h1+1] >= sza[h2] >= szde[h1])):
11
val.append(np.array(per[h2]).ravel())
12
val1.append(np.array(np.mean(val)))
13
val2.append(val1)
14
15
# val2 is gridded data
16
Let me know if any clarification is needed.
Thank You.
Advertisement
Answer
I am able to found an alternative method, which worked faster for me. I am posting as the result.
JavaScript
1
13
13
1
als = np.arange(150,510,5)
2
szde = np.arange(90,190,5)
3
4
res=[]
5
for h in range(len(als)-1):
6
tempu=[]
7
for h2 in range(len(szde)-1):
8
a11=np.logical_and((alt<als[h+1]),(alt>als[h]))
9
a22=np.logical_and((sza<szde[h2+1]),(sza>szde[h2]))
10
tempu.append(np.nanmean(per[np.where(np.logical_and(a11,a22)==True)]))
11
res.append(tempu)
12
res=np.array(res)
13
res is the gridded array of (72,19)