Notebook Linear Algebra
Notebook Linear Algebra
1 Linear Algebra
Linear algebra is the branch of mathematics that deals with vector spaces.
1.1 Vectors
Abstractly, vectors are objects that can be added together (to form new vectors) and that can be
multiplied by scalars (i.e., numbers), also to form new vectors.
For example, if you have the heights, weights, and ages of a large number of people, you can treat
your data as three-dimensional vectors (height, weight, age) . If you’re teaching a class with four
exams, you can treat student grades as four- dimensional vectors (exam1, exam2, exam3, exam4) .
print("v = ", v)
print("w = ", w)
l1 = [1, 2, 1, 4, 5]
l2 = [6, 5, 7, 4, 9]
vector_add(l1,l2)
v = [1, 2, 1, 4, 5]
w = [6, 5, 7, 4, 9]
v + w = [7, 7, 8, 8, 14]
# initializing lists
name = [ "Manjeet", "Nikhil", "Shambhavi", "Astha" ]
roll_no = [ 4, 1, 3, 2 ]
marks = [ 40, 50, 60, 70 ]
1
mapped = zip(name, roll_no, marks)
print("v = ", v)
print("w = ", w)
l1 = [1, 2]
l2 = [6, 5]
dot(l1,l2)
v = [1, 2]
w = [6, 5]
v1 * w2 + v2 *w2 = 16
scalar_multiply(3,[1,2,3])
v = [1, 2, 3]
c = 3
c * v = [3, 6, 9]
1.2 Matrices
A matrix is a two-dimensional collection of numbers. We will represent matrices as list s of list s,
with each inner list having the same size and representing a row of the matrix. If A is a matrix,
then A [i] [j] is the element in the ith row and the jth column. Per mathematical convention, we
will typically use capital letters to represent matrices. For example:
2
[5]: A = [[1, 2, 3], # A has 2 rows and 3 columns
[4, 5, 6]]
[6]: print(A)
[8]: B
[9]: c = []
[11]: shape(A)
[11]: (2, 3)
# Initialize matrix
matrix = []
print("Enter the entries row wise:")
3
for j in range(C):
print(matrix[i][j], end = " ")
print()
print("Matrix 1:")
print("-"*9)
for i in mat1:
print(i)
print("="*15)
print("Matrix 2:")
print("-"*9)
for i in mat2:
print(i)
mat3 = [[0,0,0],
[0,0,0],
[0,0,0]]
matrix_length = len(mat1)
print("="*15)
print("Matrix 1 * Matrix 2:")
print("-"*21)
#To Print the matrix
for i in mat3:
print(i)
[ ]: