Skip to content

Commit 80928bd

Browse files
authored
Update flat.md
1 parent e959f37 commit 80928bd

File tree

1 file changed

+8
-8
lines changed
  • content/numpy/concepts/ndarray/terms/flat

1 file changed

+8
-8
lines changed

content/numpy/concepts/ndarray/terms/flat/flat.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ Subjects:
55
- 'Computer Science'
66
- 'Data Science'
77
Tags:
8-
- 'Array'
9-
- 'Iterator'
8+
- 'Arrays'
9+
- 'Iterators'
1010
- 'NumPy'
1111
CatalogContent:
1212
- 'learn-python-3'
1313
- 'paths/data-science'
1414
---
1515

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.
1717

1818
## Syntax
1919

@@ -78,18 +78,18 @@ Array after assignment via .flat:
7878

7979
## Codebyte Example
8080

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`:
8282

8383
```codebyte/python
8484
import numpy as np
8585
8686
my_array = np.array([
87-
[10, 11],
88-
[20, 21],
89-
[30, 31]
87+
[10, 11],
88+
[20, 21],
89+
[30, 31]
9090
])
9191
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])
9393
flat_index_3 = my_array.flat[3]
9494
9595
print(f"Original array shape: {my_array.shape}")

0 commit comments

Comments
 (0)