1

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)
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.