简体   繁体   English

我如何遍历切片的ndarray

[英]How do i loop through a sliced ndarray

` `

     pix = cv2.imread(dirname2)
     pix=pix.reshape((1,144,256,3))

     pix[0:10,:,:,:]=pix[0:10,:,:,:]*0

     print(pix)

     framestack=[]

     for x in range(0,10):

         pix[x,:,:,:,:]=255
         pix[0:10,:,:,:]=pix[0:10,:,:,:]*0
                                   `

Hallo i would like to slice an image in such a way that when i multiply that slice by 0, i make all the first 1000 pixel channels equal to zero.你好,我想以这样一种方式对图像进行切片,当我将该切片乘以 0 时,我使所有前 1000 个像素通道都为零。

Right now it makes all the first 10 rows of the image equal to zero.现在它使图像的所有前 10 行都为零。

then within the loop i would like to turn on each pixel channels value to 255 in turn, one after the other, but turning the values back to zero for previous itterations or slots when progressing.然后在循环中,我想依次将每个像素通道的值打开为 255,一个接一个,但在进行时将先前的迭代或槽的值转回零。 from those 1000 pixel channels we made equal to zero.从我们使等于零的那 1000 个像素通道中。 My problem is heavily flawed slicing technique.我的问题是切片技术存在严重缺陷。

Iterate over nth dimension:迭代第 n 维:

for x in np.rollaxis(data, n+1):
    print(x)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM