-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02.numpy-tutorial.py
More file actions
57 lines (33 loc) · 786 Bytes
/
Copy path02.numpy-tutorial.py
File metadata and controls
57 lines (33 loc) · 786 Bytes
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
import numpy as np
A = np.array([[1, 1],
[0, 1]])
B = np.array([[2, 0],
[3, 4]])
print(A)
print(B)
print(A.shape)
print(B.shape)
print(A * B) # element-wise product
print(A @ B) # matrix product
print(A.dot(B)) # another matrix product
print(np.ones((3, 5, 4), dtype=float))
print(np.arange(12))
b = np.arange(12).reshape((3, 4))
print(b)
print(b.sum(axis=0)) # sum of each column
print(b.min(axis=1)) # min of each row
print(b)
print(b.T) # returns the array, transposed
print(b.ravel()) # returns the array, flattened
print(np.vstack((b, b)))
print(np.hstack((b, b)))
print(b[0, 1])
print(b[:, 1])
print(b[:, 1:3])
print(b < 5)
print(b[b < 5])
b[b < 5] = 0
print(b)
a = np.random.randint(0, 10, 5)
print(a)
print(np.sort(a))