What is the transpose of a vector?
We know that a row vector can be represented using a 1xn matrix. And a column vector can be represented using an nx1 matrix. Let’s say v1 is a row vector and v2 is a column vector. And v1 and v2 have the following components:
If we take the transpose of a row vector, then the row vector becomes a column vector with the same components. And if we take the transpose of a column vector, then the column vector becomes a row vector with the same components.
So, if we take the transpose of v1 and v2, then v1T and v2T will become like the following:
and
How to calculate the transpose of a vector using Python NumPy?
We can use the transpose() function in NumPy to calculate the transpose of a vector. For example, we can use the following Python code to calculate the transpose of a row vector or a column vector.
import numpy r = numpy.random.randint(low=1, high=10, size=(1, 3)) c = numpy.random.randint(low=1, high=10, size=(3, 1)) r_transpose = r.transpose() c_transpose = c.transpose() print("r: \n", r) print("Transpose of r: \n", r_transpose) print("c: \n", c) print("Transpose of c: \n", c_transpose)
Here, we are using the numpy.random.randint() function to create a row vector r and a column vector c with random integers. Please note that the low and the high arguments indicate that the generated numbers will be within the range [low, high).
And the size argument indicates the shape of the created vector. (1, 3) indicates the vector will have three components in a single row. In other words, the vector will be a row vector. And (3, 1) indicates the vector will have 3 components in a single column. In other words, the vector will be a column vector.
Now, we are using the transpose() function to take the transpose of a vector. The output of the mentioned program will be:
r: [[3 3 5]] Transpose of r: [[3] [3] [5]] c: [[7] [7] [9]] Transpose of c: [[7 7 9]]






0 Comments