Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.

Commit ec355dd

Browse files
committed
Update
1 parent 2ed0c7b commit ec355dd

File tree

3 files changed

+80
-65
lines changed

3 files changed

+80
-65
lines changed

lessons/python/modules/numpy/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616
- `V: byte-like object` ??
1717
- [Convert Data Type](numpy_convert_data_type.py)
1818
- `.astype()`
19-
- [Access](numpy_access.py)
20-
- `.base` <sub>check if returned array is copy or view</sub>
21-
- `np.nditer(array), np.ndenumerate(array)`
2219
- [Functions](numpy_functions.py)
2320
- `.reshape()`
2421
- `np.concatenate()`
2522
- `np.stack(), np.hstack(), np.vstack(), np.dstack()`
23+
- [`np.nditer(array), np.ndenumerate(array)`](numpy_access.py)
2624
- Filter
2725
- [Where](numpy_filter_values.py)
2826
- Access
2927
- [One Row](numpy_access_one_row.py)
3028
- [One Column](numpy_access_one_column.py)
3129
- [Box](numpy_access_range.py)
32-
- [`.copy()` va `.view()`](numpy_access_copy_view.py)
30+
- [`.copy()` va `.view()`, `.base`](numpy_access_copy_view.py) <sub>check if returned array is copy or view</sub>
31+
- Math
Lines changed: 42 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,61 @@
11
import numpy as np
22

33
# ------------------------------------------------------------------
4-
# View, Copy
5-
my_array = np.array([1, 2, 3, 4, 5])
6-
my_array_copy = my_array.copy()
7-
my_array_view = my_array.view()
4+
# Iterate
85

96

10-
my_array_copy[0] = 100
11-
print(my_array, my_array_copy, my_array_copy.base)
12-
# [1 2 3 4 5] [100 2 3 4 5] None
7+
L = [
8+
[1, 2, 3, 4, 5],
9+
[1, 2, 3, 4, 6],
10+
[1, 2, 3, 4, 7],
11+
[1, 2, 3, 4, 8],
12+
]
1313

14+
N = np.array(L)
1415

15-
my_array_view[0] = 100
16-
print(my_array, my_array_view, my_array_view.base)
17-
# [100 2 3 4 5] [100 2 3 4 5] [100 2 3 4 5]
1816

17+
for x in N:
18+
for y in x:
19+
print(y, end=" - ")
20+
# 1 - 2 - 3 - 4 - 5 - 1 - 2 - 3 - 4 - 6 - 1 - 2 - 3 - 4 - 7 - 1 - 2 - 3 - 4 - 8 -
1921

20-
# ------------------------------------------------------------------
21-
# Iterate
2222

23+
print()
2324

24-
my_array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
25-
my_array = my_array.reshape(2, 3, -1)
2625

26+
for x in N.reshape(-1):
27+
print(x, end=" * ")
28+
# 1 * 2 * 3 * 4 * 5 * 1 * 2 * 3 * 4 * 6 * 1 * 2 * 3 * 4 * 7 * 1 * 2 * 3 * 4 * 8 *
2729

28-
for x in my_array:
29-
for y in x:
30-
for z in y:
31-
print(z)
32-
"""
33-
1
34-
2
35-
3
36-
4
37-
5
38-
6
39-
7
40-
8
41-
9
42-
10
43-
11
44-
12
45-
"""
4630

31+
print()
32+
33+
34+
for x in np.nditer(N):
35+
print(x, end=" ^ ")
36+
# 1 ^ 2 ^ 3 ^ 4 ^ 5 ^ 1 ^ 2 ^ 3 ^ 4 ^ 6 ^ 1 ^ 2 ^ 3 ^ 4 ^ 7 ^ 1 ^ 2 ^ 3 ^ 4 ^ 8 ^
4737

48-
for item in np.nditer(my_array):
49-
print(item)
50-
"""
51-
1
52-
2
53-
3
54-
4
55-
5
56-
6
57-
7
58-
8
59-
9
60-
10
61-
11
62-
12
63-
"""
6438

65-
for index, item in np.ndenumerate(my_array):
39+
for index, item in np.ndenumerate(N):
6640
print(index, item)
6741
"""
68-
(0, 0, 0) 1
69-
(0, 0, 1) 2
70-
(0, 1, 0) 3
71-
(0, 1, 1) 4
72-
(0, 2, 0) 5
73-
(0, 2, 1) 6
74-
(1, 0, 0) 7
75-
(1, 0, 1) 8
76-
(1, 1, 0) 9
77-
(1, 1, 1) 10
78-
(1, 2, 0) 11
79-
(1, 2, 1) 12
42+
(0, 1) 2
43+
(0, 2) 3
44+
(0, 3) 4
45+
(0, 4) 5
46+
(1, 0) 1
47+
(1, 1) 2
48+
(1, 2) 3
49+
(1, 3) 4
50+
(1, 4) 6
51+
(2, 0) 1
52+
(2, 1) 2
53+
(2, 2) 3
54+
(2, 3) 4
55+
(2, 4) 7
56+
(3, 0) 1
57+
(3, 1) 2
58+
(3, 2) 3
59+
(3, 3) 4
60+
(3, 4) 8
8061
"""
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import numpy as np
2+
3+
L = [
4+
[1, 2, 3, 4, 5],
5+
[1, 2, 3, 4, 6],
6+
[1, 2, 3, 4, 7],
7+
[1, 2, 3, 4, 8],
8+
]
9+
10+
N = np.array(L)
11+
12+
C = N.copy()
13+
V = N.view()
14+
15+
V[0, 0] = 100
16+
print(N)
17+
18+
C[0, 0] = -1
19+
print(N)
20+
print(C)
21+
22+
23+
print(N.base)
24+
# None
25+
26+
print(V.base)
27+
'''
28+
[[100 2 3 4 5]
29+
[ 1 2 3 4 6]
30+
[ 1 2 3 4 7]
31+
[ 1 2 3 4 8]]
32+
'''
33+
34+
print(C.base)
35+
# None

0 commit comments

Comments
 (0)