Skip to content

Instantly share code, notes, and snippets.

@yuitest
Created March 23, 2015 16:24
Show Gist options
  • Save yuitest/8c51c62a58ef624c5832 to your computer and use it in GitHub Desktop.
Save yuitest/8c51c62a58ef624c5832 to your computer and use it in GitHub Desktop.
import numpy as np
mytype = [('id', 'uint32'), ('x', 'float64'), ('y', 'float64')]
a = np.array([(1, 0.5, 0.3), (3, 0.2, 0.1),
(5, 0.1, 0.3), (8, 0.1, 0.5)], dtype=mytype)
c = a[['x', 'y']]
b = c.view(np.float64).reshape(c.shape + (-1,))
relavancy = np.linalg.norm(b[:, np.newaxis] - b, axis=2)
print(relavancy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment