IndentationError: expected an indented block如何处理

在做到cs231n的assignment1的第一个KNN作业时,跑如下代码反的时候:

    def compute_distances_one_loop(self, X):
        """
        Compute the distance between each test point in X and each training point
        in self.X_train using a single loop over the test data.

        Input / Output: Same as compute_distances_two_loops
        """
        num_test = X.shape[0]
        num_train = self.X_train.shape[0]
        dists = np.zeros((num_test, num_train))
        for i in xrange(num_test):
            #######################################################################
            # TODO:                                                               #
            # Compute the l2 distance between the ith test point and all training #
            # points, and store the result in dists[i, :].                        #
            #######################################################################
            # pass
            #######################################################################
            #                         END OF YOUR CODE                            #
            #######################################################################
        return dists

一直提示错误:

Traceback (most recent call last):

  File "/opt/anaconda3/envs/tensorflow/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3417, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-110-833c0369b4cf>", line 1, in <module>
    from cs231n.classifiers import KNearestNeighbor

  File "/Users/shili/Downloads/assignment1/cs231n/classifiers/__init__.py", line 1, in <module>
    from cs231n.classifiers.k_nearest_neighbor import *

  File "/Users/shili/Downloads/assignment1/cs231n/classifiers/k_nearest_neighbor.py", line 119
    return dists
         ^
IndentationError: expected an indented block

最后发现,在第一段for循环里面,我把pass给注释掉了。

但是不能注释pass!

即使这个循环留空,也不能什么都不写,也要写一个pass。否则就会报以上的错误!


版权声明:本文为qwaszx3793原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。