Connect your moderator Slack workspace to receive post notifications:
Sign in with Slack

Exercise 1, Task B

Hi!

For the task B I have a question about the solution:
def with_indices(p, q):
rows, cols = np.indices((p.shape[0], q.shape[0]))
distances = np.sqrt(np.sum((p[rows.ravel(), :] - q[cols.ravel(), :])**2, axis=1))
return distances.reshape((p.shape[0], q.shape[0]))

Is it necessary to use slicing for p[rows.ravel(), :]? Could we not just use p[rows.ravel()]?

Thank you!

If you try:

np.allclose(p[rows.ravel(),:], p[rows.ravel()])

You get True, they are the same, you can drop the ":" as you want the rows, if you would want the column then you would need something like p[:,np.array([0,1])].

Page 1 of 1

Add comment

Post as Anonymous Dont send out notification