Python vectorizing nested for loops
Approach #1 Here’s a vectorized approach – m,n,r = volume.shape x,y,z = np.mgrid[0:m,0:n,0:r] X = x – roi[0] Y = y – roi[1] Z = z – roi[2] mask = X**2 + Y**2 + Z**2 < radius**2 Possible improvement : We can probably speedup the last step with numexpr module – import numexpr as ne … Read more