How to make a checkerboard in numpy?

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

    import numpy as np
    x = np.ones((3,3))
    print("Checkerboard pattern:")
    x = np.zeros((8,8),dtype=int)
    # (odd_rows, even_columns)
    x[1::2,::2] = 1
    # (even_rows, odd_columns)
    x[::2,1::2] = 1
    print(x)
    

提交回复
热议问题