# create array of the same size as "A" and # fill it with distances from (xc,yc). # array R is the output. def dist(A,xc,yc): import numpy as np xy=np.shape(A) nx=xy[1] ; ny=xy[0] # x & y dimensions of A arow=np.arange(0,nx,1)-xc # x-distance of point from xc acol=np.arange(0,ny,1)-yc # y-distance of point from yc acol=acol.reshape((-1,1)) # make acol a column vector mcol=np.hstack(nx*[acol]) # matrix filled with columns mrow=np.vstack(ny*[arow]) # matrix filled with rows R=np.sqrt(mrow**2 + mcol**2) # Pythagoras! return R