【发布时间】:2026-02-11 15:00:01
【问题描述】:
我一直在仔细阅读文档并重新阅读/运行以下代码,以便准确了解正在发生的事情。不过我的知识还是有差距的。我想用 cmets 向你展示代码,这表示我的知识空白,希望你们中的一些人愿意填补。
所以这是我的请求朋友:
1)帮助我填补我的知识空白
2)以非技术性和简单的格式逐步解释这里发生的事情。
import numpy
import scipy.misc
import matplotlib.pyplot
lena = scipy.misc.lena()
''' Generates an artificial range within the framework of the original array (Which is an image)
This artificial range will be paired with another one and used to 'climb'
Through the original array and make changes'''
def get_indices(size):
arr = numpy.arange(size)
#This sets every fourth element to False? How?
return arr % 4 == 0
lena1 = lena.copy()
xindices = get_indices(lena.shape[0])
yindices = get_indices(lena.shape[1])
'''I am unsure of HOW the below code is executing. I know something is being
Set to zero, but what? And how can I verify it?'''
lena[xindices, yindices] = 0
#What does the argument 211 do exactly?
matplotlib.pyplot.subplot(211)
matplotlib.pyplot.imshow(lena1)
matplotlib.pyplot.show()
谢谢小伙伴们!
【问题讨论】:
-
您是否尝试了解
scipy.misc.lena返回的内容?您在哪里或为什么被卡住了? -
是的,我明白了。对我来说最令人困惑的部分是“lena[xindices, yindices] = 0”
-
a[i, j]只是a[i][j]的一种说法,即索引多维数组。 docs.scipy.org/doc/numpy/reference/arrays.indexing.html -
您的其他问题之一回答了其中一些问题
标签: python python-3.x numpy scipy