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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.