How to make a checkerboard in numpy?

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

    Can't you use hstack and vstack? See here. Like this:

    >>> import numpy as np
    >>> b = np.array([0]*4)
    >>> b.shape = (2,2)
    >>> w = b + 0xAA
    >>> r1 = np.hstack((b,w,b,w,b,w,b))
    >>> r2 = np.hstack((w,b,w,b,w,b,w))
    >>> board = np.vstack((r1,r2,r1,r2,r1,r2,r1))
    

提交回复
热议问题