Checkerboard pattern for n = 8:
It consists of n * n squares alternating 0 for white and 1 for black.
We can do the same using x = np.zeros ((n, n), dtype = int) Using this function, we initialize 2-D a matrix with zeros at all indices using Exit: # Python nXn print program
# checkerboard pattern using numpy
import
numpy as np
# function for printing a checkerboard
def
printcheckboard (n):
print
(
"Checkerboard pattern:"
)
# create * n matrix
x
=
np.zeros ((n, n) , dtype
=
int
)
# fill in 1 alternate rows and columns
x [
1
::
2
, ::
2
]
=
1
x [::
2
,
1
::
2
]
=
1
c ode>
# print template
for
i
in
range
(n):
for
j
in
range
(n):
print
(x [i] [j], end
=
""
)
print
( )
# driver code
n
= cod e>
8
printcheckboard (n)
Checkerboard pattern: 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