What is a zero matrix?
A zero matrix is a matrix in which all elements are equal to zero. So, an mxn zero matrix will have mn elements and all the elements will be equal to 0. For example, the matrices mentioned below are zero matrices.
Here, A is a 2×2 zero matrix. B is a 2×3 zero matrix. And C is a 4×3 zero matrix.
How to create a zero matrix using Python NumPy?
We can use the following Python code to create a zero matrix using NumPy.
import numpy m = 3 n = 4 A = numpy.zeros(shape=(m, n)) print("A: \n", A)
Here, we are using the function numpy.zeros() to create a matrix containing all zeros. The shape argument specifies the shape of the matrix. For example, shape=(m, n) specifies that the created matrix will have m rows and n columns.
The output of the mentioned program will be:
A: [[0. 0. 0. 0.] [0. 0. 0. 0.] [0. 0. 0. 0.]]






0 Comments