I am using the below code to calculate standard deviation azimuthally for 2D array converted from images. However, the code takes couple minutes to run. Can anyone suggest how this can be made faster?
import numpy as np
def radial_profile(data, center):
y, x = np.indices((data.shape))
r = np.sqrt((x - center[0])**2 + (y - center[1])**2)
r = r.astype(np.int64)
radialprofile = np.zeros(np.max(r) + 1)
for i in range (np.max(r) + 1):
radialprofile[i] = np.std(data[r == i])
return radialprofile
data = random.randint(10, size=(4096, 4096))
std_azi = radial_profile(data, [2048,2048])
CPU times: total: 1min 1s
Wall time: 1min 1s
As you can see in the CPU and Wall time, it takes at least a minute to run this. I have 10,000 such astronomical images that needs to be processed. So, any suggestion on how this code can be made faster would be highly appreciated.