Going through the Python Data Science Handbook and I'm having trouble understanding the array broadcasting to find distance between two points.
Could anyone please explain the logic for adding the new axis in the below code?
X = rand.rand(10, 2)
dist_sq = np.sum((X[:, np.newaxis, :] - X[np.newaxis, :, :]) ** 2, axis=-1)