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。否则就会报以上的错误!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值