forked from blksail-edu/python-refresher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinear_algebra.py
More file actions
59 lines (51 loc) · 1.23 KB
/
Copy pathlinear_algebra.py
File metadata and controls
59 lines (51 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import numpy as np
def sumDiff(a, b):
sum = a + b
diff = a - b
print(f"\na = \n{a}")
print(f"\nb = \n{b}")
print(f"\nsum = \n{sum}")
print(f"\ndifference = \n{diff}")
#Problem 1
print("Problem 1:")
a = np.array([[1], [2], [3]])
b = np.array([[4], [5], [6]])
sumDiff(a, b)
#Problem 2
print("\n\nProblem 2:")
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])
sum = a + b
diff = a - b
print(f"\na = \n{a}")
print(f"\nb = \n{b}")
print(f"\nsum = \n{sum}")
print(f"\ndifference = \n{diff}")
#Problem 3
print("\n\nProblem 3:")
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
dotProduct = np.dot(a, b)
print(f"\na = {a}")
print(f"\nb = {b}")
print(f"\nDot product = {dotProduct}")
#Problem 4
print("\n\nProblem 4:")
a = np.array([[1, 2, 3], [4, 5, 6]])
b = np.array([[7, 8, 9, 10], [11, 12, 13, 14], [15, 16, 17, 18]])
product = np.dot(a, b)
print(f"\na = \n{a}")
print(f"\nb = \n{b}")
print(f"\nproduct = \n{product}")
#Problem 5
print("\n\nProblem 5:")
a = np.array([1, 1, 2])
magnitude = np.linalg.norm(a)
print(f"\na = {a}")
print(f"\nmagnitude = {magnitude}")
#Problem 6
print("\n\nProblem 6:")
a = np.array([[1, 3], [2, 4]])
transpose = np.transpose(a)
print(f"\na = \n{a}")
print(f"\ntranspose = \n{transpose}")