Defining Matrix using Numpy | Linear Algebra using Python

Linear Algebra using Python | Defining Matrix using Numpy: Here, we are going to learn how to define matrix 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. Matrix is the key to linear algebra. All the linear algebra revolves around matrices. In previous tutorials, we defined the vector using the list and then with numpy. 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 use numpy.

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

Python code for Defining Matrix using Numpy

# Linear Algebra Learning Sequence
# Defining a matrix using numpy

import numpy as np

# Use of np.array() to define a matrix
V1 = np.array([[1,2,3],[2,3,5],[3,6,8]])
V2 = np.array([[1,2],[3,4],[5,6]])

print("--The Matrix-- \n",V1)
print("--The Matrix-- \n",V2)

Output:

--The Matrix-- 
 [[1 2 3]
 [2 3 5]
 [3 6 8]]
--The Matrix-- 
 [[1 2]
 [3 4]
 [5 6]]





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.