Defining Vector using Numpy | Linear Algebra using Python

Linear Algebra using Python | Defining Vector using Numpy: Here, we are going to learn how to define vector using numpy in Python?
Submitted by Anuj Singh, on May 17, 2020

Linear algebra is the branch of mathematics concerning linear equations by using vector spaces and through matrices. In other words, a vector is a matrix in n-dimensional space with only one column. So vector is one of the important constituents for linear algebra. In previous tutorials, we defined the vector using the list. Defining a vector using a list is very fine and easy but it has some limitations. We can only define vectors through lists when there is only vector manipulation involved. As matrices are involved, then we have to define a vector using A supremely-optimized, well-maintained scientific computing package for Python called numpy.

Let's see how we can define a vector using this library:

Python code for Defining Vector using Numpy

# Linear Algebra Learning Sequence
# Defining a vector using numpy

import numpy as np

# Use of np.array() to define a vector
V1 = np.array([[1],[2],[3]])
V2 = np.array([[14],[23],[35],[56],[754],[123]])

# printing vectors
print("The Vector V1 = ",V1)
print("The Vector V2 = ",V2)

Output:

The Vector V1 =  [[1]
 [2]
 [3]]
The Vector V2 =  [[ 14]
 [ 23]
 [ 35]
 [ 56]
 [754]
 [123]]


Comments and Discussions!

Load comments ↻





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