How to make a checkerboard in numpy?

后端 未结 24 1295
小鲜肉
小鲜肉 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:05

    I'd use the Kronecker product kron:

    np.kron([[1, 0] * 4, [0, 1] * 4] * 4, np.ones((10, 10)))
    

    The checkerboard in this example has 2*4=8 fields of size 10x10 in each direction.

提交回复
热议问题