Skip to content

Instantly share code, notes, and snippets.

@vlavorini
Last active August 17, 2017 14:30
Show Gist options
  • Save vlavorini/922f1e581fae69925d59f12971726fd7 to your computer and use it in GitHub Desktop.
Save vlavorini/922f1e581fae69925d59f12971726fd7 to your computer and use it in GitHub Desktop.
def num(points):
expd=np.expand_dims(points,2) #need another dimension...
tiled=np.tile(expd, points.shape[0]) #...to tile up the vectors
trans=np.transpose(points) #Also need to transpose the points matrix to fit well with broadcasting
diff=trans-tiled #doing the difference, exploiting Numpy broadcasting capabilities
num=np.sum(np.square(diff), axis=1) #an then obtain the squared norm of the difference
return num
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment