Differentiating between row and column vectors

Learn, how to differentiate between row and column vectors in Python? By Pranit Sharma Last updated : October 10, 2023

NumPy is an abbreviated form of Numerical Python. It is used for different types of scientific operations in python. Numpy is a vast library in python which is used for almost every kind of scientific or mathematical operation. It is itself an array which is a collection of various methods and functions for processing the arrays.

Vectors - row vs column

Many times, we create a 1-dimensional vector and observe that the original vector and its transpose are equal.

A one-dimensional sequence of numbers is neither a row nor a column vector. A row or column vector is a two-dimensional array (in which one of the two dimensions is 1).

Hence, we can make the distinction explicit by adding another dimension to the array. For this purpose, we will first create an actual row or column vector. Then we will reshape the current vector and finally, we can explicitly create a row or column by making it transpose.

Let us understand with the help of an example,

Python program to demonstrate the example for differentiating between row and column vectors

# Import numpy
import numpy as np

# Creating a row vector
row = np.array([12, 3, 4, 5], ndmin=2)

# Display original row vector
print("Orignal row vector:\n",row,"\n")

# Creating a column vector
col = row.T

# Display column vector
print("Orignal column vector:\n",col,"\n")

Output

The output of the above program is:

Example: Differentiating between row and column vectors

Python NumPy Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.