-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_mathematics.py
70 lines (46 loc) · 1.25 KB
/
4_mathematics.py
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
60
61
62
63
64
65
66
67
68
69
70
import numpy as np
a = np.array([1,2,3,4])
print(a + 2) # [3 4 5 6]
print(a - 2) # [-1 0 1 2]
print(a * 2) # [2 4 6 8]
print(a / 2) # [0.5 1. 1.5 2. ]
print(a ** 2) # [ 1 4 9 16]
a += 2
print(a) # [3 4 5 6]
b = np.array([0,1,0,1])
print(a + b) # [3 5 5 7]
# Trigonomatry
print(np.sin(a)) # [ 0.14112001 -0.7568025 -0.95892427 -0.2794155 ]
print(np.cos(a)) # [-0.9899925 -0.65364362 0.28366219 0.96017029]
print(np.tan(a)) # [-0.14254654 1.15782128 -3.38051501 -0.29100619]
print(np.sinh(a)) # [ 10.01787493 27.2899172 74.20321058 201.71315737]
print(np.cosh(a)) # [ 10.067662 27.30823284 74.20994852 201.71563612]
print(np.tanh(a)) # [0.99505475 0.9993293 0.9999092 0.99998771]
# Linear algebra
a = np.ones((2, 3))
print(a)
# [[1. 1. 1.]
# [1. 1. 1.]]
b = np.full((3, 2), 2)
print(b)
# [[2 2]
# [2 2]
# [2 2]]
print(np.matmul(a, b))
# [[6. 6.]
# [6. 6.]]
# Finding determinant
c = np.identity(3)
print(np.linalg.det(c)) # 1.0
# Determinant
# Trace
# Singular Vector Decomposition
# Eigenvalues
# Matrix Norm
# Inverse
# Statics
stats = np.array([[1,2,3], [4,5,6]])
print(np.min(stats)) # 1
print(np.max(stats)) # 6
print(np.min(stats, axis=1)) # [1 4]
print(np.max(stats, axis=1)) # [3 6]