【CS231n】斯坦福大学计算机视觉学习课程笔记中Python Numpy部分遇到的问题
一.解决 ImportError: cannot import name ‘imread’ from ‘scipy.misc’
1.问题描述:
在看知乎上翻译的斯坦福CS231n计算机视觉numpy课程讲义时,出现的错误。装了pillow后还报错,装了scipy还是报错。这是由于scipy的版本问题。网上说用import imageio 替代import scipy.misc,我试了还是没用最后还是得降级scipy才能解决。
2.解决方法:
需要降级scipy到 1.2.1 版本。
重新安装低版本的 scipy:
pip3 install scipy==1.2.1
二.其它一些问题
由于该教程是用python2写的,有些地方在python3中需要修改。
比如下面的代码
def quicksort(arr):
if len(arr) <= 1:
return arr
pivot = arr[len(arr) / 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort(left) + middle + quicksort(right)
print quicksort([3,6,8,10,1,2,1])
# Prints "[1, 1, 2, 3, 6, 8, 10]"
其中arr[len(arr) / 2]
中的/需要改成//或者用int()取整,print函数需要加括号。
再有
d = {'person': 2, 'cat': 4, 'spider': 8}
for animal, legs in d.iteritems():
print 'A %s has %d legs' % (animal, legs)
# Prints "A person has 2 legs", "A spider has 8 legs", "A cat has 4 legs"
其中的for animal, legs in d.iteritems():
需要改成for animal, legs in d.items():
课程笔记链接:CS231n课程笔记翻译:Python Numpy教程