我开始使用numpy食谱自主学习numpy。我审查,并执行以下代码:使用numpy将范围设置为零
import scipy.misc
import matplotlib.pyplot
#This script demonstates fancy indexing by setting values
#On the diagnols to 0
#Load lena array
lena = scipy.misc.lena()
xmax = lena.shape[0]
ymax = lena.shape[1]
#Fancy indexing
#can set ranges of points to zero, all at once instead of using loop
lena[range(xmax), range(ymax)] = 0
lena[range(xmax-1,-1,-1), range(ymax)] = 0
matplotlib.pyplot.imshow(lena)
matplotlib.pyplot.show()
我明白在这个代码一切,除了:
我读了索引和切片the documentation但仍无法让上面的代码感。这里是我的困惑点:
1)范围(xmax)和范围(ymax)包含整个x,y轴。不会将它们设置为零会使整个图像变黑?
2)range(xmax-1,-1,-1)是什么意思?
谢谢你们!
没有在你的[上一个问题]的答案中解释#1(http://stackoverflow.com/questions/21963058/using-range-while-fancy-indexing)? #2可以用'help(range)'解释。 – DSM