How to make a checkerboard in numpy?

后端 未结 24 1186
小鲜肉
小鲜肉 2020-11-30 07:52

I\'m using numpy to initialize a pixel array to a gray checkerboard (the classic representation for \"no pixels\", or transparent). It seems like there ought to be a whizzy

24条回答
  •  有刺的猬
    2020-11-30 08:27

    I recently want the same function and i modified doug's answer a little bit as follows:

    def gen_checkerboard(grid_num, grid_size):
        row_even = grid_num/2 * [0,1]
        row_odd = grid_num/2 * [1,0]
        checkerboard = numpy.row_stack(grid_num/2*(row_even, row_odd))
        return checkerboard.repeat(grid_size, axis = 0).repeat(grid_size, axis = 1)
    

提交回复
热议问题