You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/numpy/concepts/ndarray/terms/flat/flat.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,15 +5,15 @@ Subjects:
5
5
- 'Computer Science'
6
6
- 'Data Science'
7
7
Tags:
8
-
- 'Array'
9
-
- 'Iterator'
8
+
- 'Arrays'
9
+
- 'Iterators'
10
10
- 'NumPy'
11
11
CatalogContent:
12
12
- 'learn-python-3'
13
13
- 'paths/data-science'
14
14
---
15
15
16
-
The **`flat`** attribute returns a 1-D [iterator](https://www.codecademy.com/resources/docs/python/iterators) over all elements of a multi-dimensional array, allowing access to each element as if the array were a single flat list. This is useful for loops where the dimensionality or shape of the array is irrelevant and every element needs to be processed in linear order. Iteration follows standard C-style (row-major) ordering.
16
+
The **`flat`** attribute returns a 1-D [iterator](https://www.codecademy.com/resources/docs/python/iterators) over all elements of an `ndarray`, allowing access to each element as if the array were a single flat list. This is useful for loops where the dimensionality or shape of the array is irrelevant and every element needs to be processed in linear order. Iteration follows standard C-style (row-major) ordering.
17
17
18
18
## Syntax
19
19
@@ -78,18 +78,18 @@ Array after assignment via .flat:
78
78
79
79
## Codebyte Example
80
80
81
-
Use the Codebyte below to access elements of a multi-dimensional array using a single index via `flat`:
81
+
Use the codebyte below to access elements of a multi-dimensional array using a single index via `flat`:
82
82
83
83
```codebyte/python
84
84
import numpy as np
85
85
86
86
my_array = np.array([
87
-
[10, 11],
88
-
[20, 21],
89
-
[30, 31]
87
+
[10, 11],
88
+
[20, 21],
89
+
[30, 31]
90
90
])
91
91
92
-
# Access the element at the flattened index 3 (which is element 2,1)
92
+
# Access the element at the flattened index 3 (which is element at position [1, 1])
0 commit comments