- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to print check board pattern of n*n using numpy
Given the value of n, our task is to display the check board pattern for a n x n matrix.
Different types of functions to create arrays with initial value are available in numpy . NumPy is the fundamental package for scientific computing in Python.
Algorithm
Step 1: input order of the matrix. Step 2: create n*n matrix using zeros((n, n), dtype=int). Step 3: fill with 1 the alternate rows and columns using the slicing technique. Step 4: print the matrix.
Example Code
import numpy as np def checkboardpattern(n): print("Checkerboard pattern:") x = np.zeros((n, n), dtype = int) x[1::2, ::2] = 1 x[::2, 1::2] = 1 # print the pattern for i in range(n): for j in range(n): print(x[i][j], end =" ") print() # Driver code n = int(input("Enter value of n ::>")) checkboardpattern(n)
Output
Enter value of n ::>4 Checkerboard pattern: 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0
- Related Articles
- Python program to print a checkboard pattern of n*n using numpy.
- Program to print ‘N’ alphabet using the number pattern from 1 to n in C++
- Program to check whether a board is valid N queens solution or not in python
- Python Program to Read a Number n and Print the Natural Numbers Summation Pattern
- Check if a string follows a^n b^n pattern or not in Python
- Python program to print rangoli pattern using alphabets
- Python program to print palindrome triangle with n lines
- Python Program to Read a Number n And Print the Series "1+2+…..+n= "
- Golang Program to Read a Number (n) and Print the Natural Numbers Summation Pattern
- Print n x n spiral matrix using O(1) extra space in C Program.
- C Program to print numbers from 1 to N without using semicolon
- Python program to print decimal octal hex and binary of first n numbers
- How to print a matrix of size n*n in spiral order using C#?
- Print m multiplies of n without using any loop in Python.
- Print first n distinct permutations of string using itertools in Python

Advertisements