I am making a checkerboard pattern of zeroes and ones. It would be an 8x8 array.
So far, the loop adds lists of 0,1,0,1,0,1,0,1 and 1,0,1,0,1,0,1,0 into an empty list.
z_first = np.tile([0,1], 4)
o_first = np.tile([1,0], 4)
row_number = 0
board = []
while row_number < 8:
if row_number % 2 == 0:
board.append(list(z_first))
else:
board.append(list(o_first))
row_number += 1
np.array(board)
print(board)
The output:
[[0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0]]
board.shape
throws the error “'List 'object has no attribute ‘shape.’” The checkerboard is a list despite using np.array on it. How would I make this a 2D array?