-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumpytutorial4.py
84 lines (80 loc) · 1.46 KB
/
numpytutorial4.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct 2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
import numpy as np
a=
a=np.arange(12).reshape(3,4)
a
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
for row in a:
print(row)
[0 1 2 3]
[4 5 6 7]
[ 8 9 10 11]
for cell in a.flatten:
print(cell)
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
for cell in a.flatten:
TypeError: 'builtin_function_or_method' object is not iterable
for cell in a.flatten():
print(cell)
0
1
2
3
4
5
6
7
8
9
10
11
for x in np.nditer(a,order='c')
SyntaxError: incomplete input
>>> for x in np.nditer(a,order='c'):
... print(x)
...
0
1
2
3
4
5
6
7
8
9
10
11
>>> for x in np.nditer(a,order='f'):
... print(x)
...
0
4
8
1
5
9
2
6
10
3
7
11
>>> for x in np.nditer(a,order='f',flags=[external-loop]):
... print(x)
...
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
for x in np.nditer(a,order='f',flags=[external-loop]):
NameError: name 'external' is not defined
>>> for x in np.nditer(a,order='f',flags=['external-loop']):
... print(x)
...
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
for x in np.nditer(a,order='f',flags=['external-loop']):
ValueError: Unexpected iterator global flag "external-loop"