def closestNonZeroIndex(pt, arr, kSize=<NUM_LIT>):
assert kSize % <NUM_LIT:2> == <NUM_LIT:1>, '<STR_LIT>'<EOL>hk = int(kSize / <NUM_LIT:2>)<EOL>ipt = np.asarray(pt, dtype=int)<EOL>r = [slice(max(<NUM_LIT:0>, p - hk),<EOL>min(s, p + hk + <NUM_LIT:1>)) for p, s in zip(ipt, arr.shape)]<EOL>arrr = arr[tuple(r)]<EOL>ind = np.transpose(np.nonzero(arrr))<EOL>if not len(ind):<EOL><INDENT>return None<EOL><DEDENT>center = [p - s.start for p, s in zip(ipt, r)]<EOL>ind -= center<EOL>m = np.argmin(norm(ind, axis=-<NUM_LIT:1>))<EOL>return ipt + ind[m]<EOL>
return the index closest to point [pt] in an array [arr]
within a given kernel size [kSize] that is not zero