简体   繁体   中英

How to get index from itertools.product

# loop through every NxN cell in the target image
    for (blk_row, blk_col) in itertools.product(xrange(0, height - 
      (cell_size - 1), cell_size), xrange(0, width - (cell_size - 1), cell_size)):

where N = cellsize, would it be valid to divide by cellsize to get an index?

To get the index for any iterator use enumerate :

for index, (blk_row, blk_col) in enumerate(itertools.product(
                                           xrange(0, height - (cell_size - 1), cell_size), 
                                           xrange(0, width - (cell_size - 1), cell_size))):

除以 cell_size 似乎有效,手指交叉。

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