What is a zero vector?
A zero vector is a vector that has zero magnitude and it points to undefined direction. For an n-dimensional zero vector, all the n components of the vector will be zero. For example, v1 is a two-dimensional zero vector and v2 is a three-dimensional zero vector.
How to create a zero vector using Python NumPy?
We can use the following Python code to create zero vectors using NumPy.
import numpy n = 3 v1 = numpy.zeros(shape=(1, n)) v2 = numpy.zeros(shape=(n, 1)) print("v1: \n", v1) print("v2: \n", v2)
Here, we are using the numpy.zeros() function to create a zero vector for which all the components of the vector are zeros. Please note that here v1 is an n-dimensional row vector and v2 is an n-dimensional column vector.
The output of the mentioned program will be:
v1: [[0. 0. 0.]] v2: [[0.] [0.] [0.]]






0 Comments