Complete the code to import the function that computes pairwise distances.
from scipy.spatial.distance import [1]
cdist which is for distances between two different sets.squareform which converts distance vectors to matrices.The pdist function computes pairwise distances between points in a single set.
Complete the code to compute the pairwise Euclidean distances of points in array X.
distances = [1](X, metric='euclidean')
cdist with only one array causes an error.squareform directly on the data instead of on distances.pdist computes pairwise distances within one set of points.
Fix the error in the code to convert the condensed distance vector d to a square matrix.
distance_matrix = [1](d)pdist or cdist which expect raw data, not condensed distances.euclidean which is a metric, not a function to convert formats.squareform converts condensed distance vectors to square matrices.
Fill both blanks to compute the distance matrix between two different sets X and Y using the cosine metric.
dist_matrix = [1](X, [2], metric='cosine')
pdist which only takes one array.X as the second argument instead of Y.cdist computes distances between two sets; the second argument must be the other set Y.
Fill all three blanks to create a dictionary mapping each point's index to its Euclidean distance from the origin (0,0).
origin = [0, 0] distances = {i: [1](point, [2]) for i, point in enumerate(X)} sorted_distances = sorted(distances.items(), key=lambda x: x[[3]])
cdist which requires arrays, not single points.x[0] which sorts by index, not distance.Use euclidean metric to compute distance from origin. Sorting by x[1] sorts by distance values.