python - Numpy array comparison using nditer -


the code below giving me correct answer, works when arrays (plan , meas) relatively small. when try run on arrays need compare (300x300 each), takes forever (i don't know how long because have been terminating after 45 minutes.) iterate on range of array values around index being evaluated (p). tried find documentation on nditer flag 'ranged' cannot find how implement specific range iterate through.

p = np.nditer(plan, flags = ['multi_index','common_dtype']) while not p.finished:     gam_store = 100.0     m = np.nditer(meas, flags = ['multi_index','common_dtype'])     while not m.finished:         dis_eval = np.sqrt(np.absolute(p.multi_index[0]-m.multi_index[0])**2 + np.absolute(p.multi_index[1]-m.multi_index[1])**2)                    if dis_eval <= 6.0:             = (np.absolute(p[0] - m[0]) / maxdose) **2             b = (dis_eval / gam_dist) **2             gam_eval = np.sqrt(a + b)             if gam_eval < gam_store:                 gam_store = gam_eval         m.iternext()         gamma = np.insert(gamma, location, gam_store, 0)     location = location + 1     p.iternext() 

if want iterate through small part of array, think (unless misunderstanding question) should create nditer instance slice of array.

say want array near (i,j), start this:

w = 5    # half-size of window around i, j p = np.nditer(plan[i-w:i+w, j-w:j+w], flags=...) 

this works because, say

a = array([[ 0,  1,  2,  3,  4],            [ 5,  6,  7,  8,  9],            [10, 11, 12, 13, 14],            [15, 16, 17, 18, 19],            [20, 21, 22, 23, 24]]) 

then,

w = 1 i, j = 2,2 print a[i-w:i+w+1, j-w:j+w+1] #array([[ 6,  7,  8], #       [11, 12, 13], #       [16, 17, 18]]) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -