Answer:
In order to get following pattern, we have to use numpy package.
Following code with work perfectly fine and will print the pattern.
Python code starts as below
*********************************************
<em># Python program to print 8 X 8 alternative 1 and 0's. 3rd and 4th row with all 0's
</em>
<em># checkerboard pattern using numpy
</em>
<em># We need Following pattern
</em>
<em># 0 1 0 1 0 1 0 1
</em>
<em># 1 0 1 0 1 0 1 0
</em>
<em># 0 1 0 1 0 1 0 1
</em>
<em># 0 0 0 0 0 0 0 0
</em>
<em># 0 0 0 0 0 0 0 0
</em>
<em># 1 0 1 0 1 0 1 0
</em>
<em># 0 1 0 1 0 1 0 1
</em>
<em># 1 0 1 0 1 0 1 0
</em>
<em>
</em>
<em>import numpy as np
</em>
<em>
</em>
<em># function to print Checkerboard pattern
</em>
<em>def printcheckboard(n):
</em>
<em>
</em>
<em> print(" Customized Checkerboard pattern:")
</em>
<em> # create a n * n matrix </em>
<em> x = np.zeros((n, n), dtype = int)
</em>
<em> y = np.zeros((n, n), dtype = int)
</em>
<em> # fill with 1 the alternate rows and columns
</em>
<em> x[1::2, ::2] = 1
</em>
<em> x[::2, 1::2] = 1
</em>
<em> # fill with 0 the alternate rows and columns
</em>
<em> y[1::2, ::2] = 0
</em>
<em> y[::2, 1::2] = 0
</em>
<em>
</em>
<em> # print the pattern for first 3 rows</em>
<em> for i in range(0,3):
</em>
<em> for j in range(n):
</em>
<em> print(x[i][j], end =" ")
</em>
<em> print()
</em>
<em> # print the pattern for next two rows with all 0's</em>
<em> for k in range(3,5):
</em>
<em> for l in range(n):
</em>
<em> print(y[k][l], end =" ")
</em>
<em> print()
</em>
<em> # print the pattern for last 3 rows with alternative 1 and 0. </em>
<em> for i in range(5,8):
</em>
<em> for j in range(n):
</em>
<em> print(x[i][j], end =" ")
</em>
<em> print()
</em>
<em>
</em>
<em># Calling the function code
</em>
<em>n = 8
</em>
<em>printcheckboard(n)</em>
**************************************
End of the Python Code.
Explanation:
In this you have to use Python3.7 and numpy should be installed as well in order to execute the code successfully.
2 D matrix will be created using Python numpy library and checkboard pattern is generated using array slicing.
Here n=8 and it will generate the checkerboard pattern of alternative 0 and 1. However, we need row 4th and 5th as all 0. So we have initialized two arrays matrix as x and y.
Comments in the code is self explanatory.
PS: Please make sure code is edited in IDE so that tabs or space issues can be taken care.