简体   繁体   中英

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.

Right now it makes all the first 10 rows of the image equal to zero.

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. from those 1000 pixel channels we made equal to zero. My problem is heavily flawed slicing technique.

Iterate over nth dimension:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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