-
Notifications
You must be signed in to change notification settings - Fork 0
/
computeDistances.py
31 lines (25 loc) · 1003 Bytes
/
computeDistances.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
computeDistances.py
YOUR WORKING FUNCTION for computing pairwise distances between features
"""
from scipy.spatial import distance
# you are allowed to import other Python packages above
##########################
def computeDistances(fv):
# Inputs
# fv: A N-by-D array containing D-dimensional feature vector of
# N number of data (images)
#
# Output
# D: N-by-N square matrix containing the pairwise distances between
# all samples, i.e. the first row shows the distance
# between the first sample and all other samples
# (columns)
#
#########################################################################
# ADD YOUR CODE BELOW THIS LINE
# This is the baseline distance measure: Euclidean (L2) distance
D = distance.squareform(distance.pdist(fv, 'cosine') )
# END OF YOUR CODE
#########################################################################
return D