[英]Python: Array with too many Indices?
I'm trying to understand the code below and what it does:我试图理解下面的代码及其作用:
im = pilimage.open(img_path)
image_array = np.array(im)
imgstack = image_array[area[0]:area[1],
area[2]:area[3], z_stack[0]:z_stack[1]]
I know that it opens up an image and stores it in im
and then converts im
into an array and stores that in image_array
.我知道它会打开一个图像并将其存储在
im
中,然后将im
转换为一个数组并将其存储在image_array
中。 What I don't really understand is the last part.我不太明白的是最后一部分。 I don't have that much experience with python syntax so can anyone help me.
我对 python 语法没有太多经验,所以任何人都可以帮助我。 Thank you so much!
太感谢了!
This is an advanced-ish application of the python slice notation which you can learn about here: Understanding slice notation .这是 python 切片符号的高级应用程序,您可以在此处了解:了解切片符号。 There are a couple nuances here though:
不过,这里有一些细微差别:
area[0]:area[1]
is taking the int
at these two indexes and making a slice start:end
of the image_array
following the normal rules. area[0]:area[1]
在这两个索引处获取int
并按照正常规则对image_array
进行切片start:end
。numpy
arrays support the ability to slice n-dimensions at the same time.numpy
arrays 支持同时对 n 维进行切片的能力。 https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.