简体   繁体   English

如何从 itertools.product 获取索引

[英]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?其中 N = cellsize,除以 cellsize 以获得索引是否有效?

To get the index for any iterator use enumerate :要获取任何迭代器的索引,请使用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 似乎有效,手指交叉。

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

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