Shape of Matrix | Linear Algebra using Python

Linear Algebra using Python | Shape of Matrix: Here, we are going to learn how to find shape of matrix in Python?
Submitted by Anuj Singh, on May 20, 2020

Prerequisite: Linear Algebra | Defining a Matrix

In the python code, we will add two Matrices. We can add two Matrices only and only if both the matrices have the same dimensions. Therefore, knowing the dimensions of the matrices turns out to be one of the major steps in Linear Algebra. The following code shows how an inbuilt function can be used to achieve our goal of the shape of a Matrix.

Python code for fidning Shape of Matrix

# Linear Algebra Learning Sequence
# Shape of Matrix 

import numpy as np

#Use of np.array() to define a matrix
V1 = np.array([[1,2,3],[2,3,5],[3,6,8],[323,623,823]])
V2 = np.array([[965,2413,78,44],[223,356,500,44],[312,66,78,44],[42,42,42,44],[44,44,44,44]])

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

print("\n\n Shape of the matrix A: ", V1.shape)
print(" Shape of the matrix B: ", V2.shape)

Output:

--The Matrixa A-- 
 [[  1   2   3]
 [  2   3   5]
 [  3   6   8]
 [323 623 823]]

--The Matrix B-- 
 [[ 965 2413   78   44]
 [ 223  356  500   44]
 [ 312   66   78   44]
 [  42   42   42   44]
 [  44   44   44   44]]


 Shape of the matrix A:  (4, 3)
 Shape of the matrix B:  (5, 4)





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.