I want to check which data points within X are close to each other and which are far. by calculating the distances between each other without getting to zero, is it possible?
JavaScript
x
4
1
X = np.random.rand(20, 10)
2
dist = (X - X) ** 2
3
print(X)
4
Advertisement
Answer
Using just numpy
you can either do,
JavaScript
1
2
1
np.linalg.norm((X - X[:,None]),axis=-1)
2
or,
JavaScript
1
2
1
np.sqrt(np.square(X - X[:,None]).sum(-1))
2