How to Create a Zero Matrix in Python | Previously we have developed programs to create matrix in Python now, we will discuss how to create a zero matrix in python. Matrix is a rectangular table arranged in the form of rows and columns, in the programming world we implement matrix by using arrays by classifying it as 1D and 2D arrays. In this section, there are some examples to create a zero matrix in python.
How to Create a Zero Matrix in Python
A zero matrix is a matrix that contains all 0 elements. The np.zeros() is a function in NumPy that creates a zero matrix, here dtype
is used to specify the data type of the elements.
import numpy as np
m = np.zeros([3, 3], dtype=int)
print(m)
Output:-
[[0 0 0]
[0 0 0]
[0 0 0]]
The above code creates a zero matrix with 3 rows and 3 columns.
Python Program to Create a Zero Matrix
This python program also performs the same task but in different ways. In this program, we will create a zero matrix in python without NumPy.
m, n = 2, 3
matrix = [[0] * n for i in range(m)]
Python Program Examples with Output
- Perfect Square in Python
- Absolute Value in Python
- Simple Calculator in Python
- Fibonacci Series in Python
- Get the ASCII value of Char
- Reverse a Number in Python
- Reverse a Negative Number
- Find Prime Factors in Python
- Get the First Digit of a Number
- Math.factorial() – Math Factorial
- Even Number Python Program
- Odd Number Python Program
- Even Odd Program in Python
- Multiplication Table in Python
- Leap Year Program in Python
- Fibonacci Series using Recursion
- Find Factors of a Number in Python
- Factorial of a Number using Loops
- Factorial in Python using Recursion
- Factorial using User-defined Function
- Difference Between Two Numbers
- Solve Quadratic Equation in Python
- Sum of Digits of a Number in Python
- Find Largest of 3 Numbers in Python
- Sum of N Natural Numbers in Python
- Average of N Numbers in Python
- Find Sum of N Numbers in Python
- Count Number of Digits in a Number
- Find LCM of Two Numbers in Python
- HCF or GCD of 2 Numbers in Python
- Print ASCII Table in Python
- Pandas Divide Two Columns
- Check Vowel or Consonant in Python
- Check Whether Character is Alphabet
Python Conversion Programs