Skip to content

Commit

Permalink
Merge pull request #1 from Ja1r0/patch-1
Browse files Browse the repository at this point in the history
Update k_nearest_neighbor.py
  • Loading branch information
Halfish committed Dec 26, 2017
2 parents f10dd61 + 4e4e833 commit d355c0c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions assignment1/cs231n/classifiers/k_nearest_neighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def compute_distances_two_loops(self, X):
# not use a loop over dimension. #
#####################################################################
pass
dists[i][j] = np.sum((X[i] - self.X_train[j]) ** 2)
dists[i][j] = np.sqrt(np.sum((X[i] - self.X_train[j]) ** 2))
#####################################################################
# END OF YOUR CODE #
#####################################################################
Expand All @@ -95,7 +95,7 @@ def compute_distances_one_loop(self, X):
# points, and store the result in dists[i, :]. #
#######################################################################
pass
dists[i] = np.sum((self.X_train - X[i]) ** 2, 1)
dists[i] = np.sqrt(np.sum((self.X_train - X[i]) ** 2, 1))
#######################################################################
# END OF YOUR CODE #
#######################################################################
Expand Down Expand Up @@ -127,6 +127,7 @@ def compute_distances_no_loops(self, X):
dists += np.sum(self.X_train ** 2, axis=1).reshape(1, num_train)
dists += np.sum(X ** 2, axis=1).reshape(num_test, 1) # reshape for broadcasting
dists -= 2 * np.dot(X, self.X_train.T)
dists = np.sqrt(dists)
#########################################################################
# END OF YOUR CODE #
#########################################################################
Expand Down

0 comments on commit d355c0c

Please sign in to comment.