I am using the metpy package to calculate many different weather parameters for many different locations across North America for many different hours. I want to fill arrays containing these weather parameters that look like: [hrs,stns]. I am not able to vectorize these operations, unfortunately (see metpy package documentation and notice that many of these calculations cannot operate on the original arrays this data normally comes in).
Here is a very simple example of my code. How would I run the following code in parallel?
wx_array1 = np.empty(shape=(3000,600))
wx_array2 = np.empty(shape=(3000,600))
for hr in range(3000):
for stn in range(600):
wx_array1[hr,stn] = hr * stn
wx_array2[hr,stn] = hr + stn
3
You could use Numba package to speed-up calculations:
Normal: 962 ms ± 228 ms per loop
With numba: 3.77 ms ± 52 µs per loop
import numpy as np
import numba
wx_array1 = np.empty(shape=(3000,600))
wx_array2 = np.empty(shape=(3000,600))
@numba.jit()
def create_array(wx_array1, wx_array2):
for hr in range(3000):
for stn in range(600):
wx_array1[hr,stn] = hr * stn
wx_array2[hr,stn] = hr + stn
return wx_array1, wx_array2
create_array(wx_array1, wx_array2)