From 13829732888a012ee5b198564e211ddd6375f34d Mon Sep 17 00:00:00 2001 From: Lingamuneni Santhosh Siddhardha <103999924+Santhosh-Siddhardha@users.noreply.github.com> Date: Tue, 28 May 2024 21:01:23 +0530 Subject: [PATCH 01/10] Create numpy_array_iteration.md Added Introduction Added Basic Iteration Added nditer Added ndenumerate Added flat Added Conclusion --- contrib/pandas/numpy_array_iteration.md | 109 ++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 contrib/pandas/numpy_array_iteration.md diff --git a/contrib/pandas/numpy_array_iteration.md b/contrib/pandas/numpy_array_iteration.md new file mode 100644 index 0000000..ac35d95 --- /dev/null +++ b/contrib/pandas/numpy_array_iteration.md @@ -0,0 +1,109 @@ +# NumPy Array Iteration + +Iterating over arrays in NumPy is a common task when processing data. NumPy provides several ways to iterate over elements of an array efficiently. +Understanding these methods is crucial for performing operations on array elements effectively. + +## 1. Basic Iteration + +- Iterating using basic `for` loop. + +**Single-dimensional array iteration**: + +Iterating over a single-dimensional array is straightforward using a basic `for` loop + +```python +import numpy as np + +arr = np.array([1, 2, 3, 4, 5]) +for i in arr: + print(i) +``` +**Output** : +```python +[ 1 2 3 4 5 ] +``` +**Multi-dimensional array**: + +Iterating over multi-dimensional arrays, each iteration returns a sub-array along the first axis. + +```python +marr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) + +for arr in marr: + print(arr) +``` +**Output** : +```python +[1 2 3] +[4 5 6] +[7 8 9] +``` + +## 2. Iterating with nditer + +- `nditer` is a powerful iterator provided by NumPy for iterating over multi-dimensional arrays. +- In each interation it gives each element. + +```python +import numpy as np + +arr = np.array([[1, 2, 3], [4, 5, 6]]) +for i in np.nditer(arr): + print(i) +``` +**Output** : +```python +1 +2 +3 +4 +5 +6 +``` + +## 3. Iterating with ndenumerate + +- `ndenumerate` allows you to iterate with both the index and the value of each element. +- It gives index and value as output in each iteration + +```python +import numpy as np + +arr = np.array([[1, 2], [3, 4]]) +for index,value in np.ndenumerate(arr): + print(index,value) +``` + +**Output** : + +```python +(0, 0) 1 +(0, 1) 2 +(1, 0) 3 +(1, 1) 4 +``` + +## 4. Iterating with flat + +- The `flat` attribute returns a 1-D iterator over the array. +- + +```python +import numpy as np + +arr = np.array([[1, 2], [3, 4]]) +for element in arr.flat: + print(element) +``` + +**Output** : + +```python +1 +2 +3 +4 +``` + +Understanding the various ways to iterate over NumPy arrays can significantly enhance your data processing efficiency. +Whether you are working with single-dimensional or multi-dimensional arrays, NumPy provides versatile tools to iterate and manipulate array elements effectively. From 6c5f9d9fd7acc118339a00b7c33045028f2e895b Mon Sep 17 00:00:00 2001 From: Lingamuneni Santhosh Siddhardha <103999924+Santhosh-Siddhardha@users.noreply.github.com> Date: Tue, 28 May 2024 21:03:35 +0530 Subject: [PATCH 02/10] Update index.md Added Numpy Array Iteration --- contrib/pandas/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/pandas/index.md b/contrib/pandas/index.md index c71c324..0af05c7 100644 --- a/contrib/pandas/index.md +++ b/contrib/pandas/index.md @@ -7,3 +7,4 @@ - [Excel using Pandas DataFrame](excel_with_pandas.md) - [Importing and Exporting Data in Pandas](import-export.md) - [Handling Missing Values in Pandas](handling-missing-values.md) +- [NumPy Array Iteration](numpy-array-iteration.md) From b31bfc61498761a219a3be2896633e3d6624ad67 Mon Sep 17 00:00:00 2001 From: Lingamuneni Santhosh Siddhardha <103999924+Santhosh-Siddhardha@users.noreply.github.com> Date: Tue, 28 May 2024 21:04:45 +0530 Subject: [PATCH 03/10] Update index.md --- contrib/pandas/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/pandas/index.md b/contrib/pandas/index.md index 0af05c7..9bf59a3 100644 --- a/contrib/pandas/index.md +++ b/contrib/pandas/index.md @@ -7,4 +7,4 @@ - [Excel using Pandas DataFrame](excel_with_pandas.md) - [Importing and Exporting Data in Pandas](import-export.md) - [Handling Missing Values in Pandas](handling-missing-values.md) -- [NumPy Array Iteration](numpy-array-iteration.md) +- [NumPy Array Iteration](numpy_array_iteration.md) From 5280fb09a8b8cb7118b1cddee2f045eeea9cc4ee Mon Sep 17 00:00:00 2001 From: Lingamuneni Santhosh Siddhardha <103999924+Santhosh-Siddhardha@users.noreply.github.com> Date: Tue, 28 May 2024 21:28:52 +0530 Subject: [PATCH 04/10] Create numpy_array_iteration.md Added Introduction Added Methods Added examples Added Conclusion --- contrib/numpy/numpy_array_iteration.md | 109 +++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 contrib/numpy/numpy_array_iteration.md diff --git a/contrib/numpy/numpy_array_iteration.md b/contrib/numpy/numpy_array_iteration.md new file mode 100644 index 0000000..ac35d95 --- /dev/null +++ b/contrib/numpy/numpy_array_iteration.md @@ -0,0 +1,109 @@ +# NumPy Array Iteration + +Iterating over arrays in NumPy is a common task when processing data. NumPy provides several ways to iterate over elements of an array efficiently. +Understanding these methods is crucial for performing operations on array elements effectively. + +## 1. Basic Iteration + +- Iterating using basic `for` loop. + +**Single-dimensional array iteration**: + +Iterating over a single-dimensional array is straightforward using a basic `for` loop + +```python +import numpy as np + +arr = np.array([1, 2, 3, 4, 5]) +for i in arr: + print(i) +``` +**Output** : +```python +[ 1 2 3 4 5 ] +``` +**Multi-dimensional array**: + +Iterating over multi-dimensional arrays, each iteration returns a sub-array along the first axis. + +```python +marr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) + +for arr in marr: + print(arr) +``` +**Output** : +```python +[1 2 3] +[4 5 6] +[7 8 9] +``` + +## 2. Iterating with nditer + +- `nditer` is a powerful iterator provided by NumPy for iterating over multi-dimensional arrays. +- In each interation it gives each element. + +```python +import numpy as np + +arr = np.array([[1, 2, 3], [4, 5, 6]]) +for i in np.nditer(arr): + print(i) +``` +**Output** : +```python +1 +2 +3 +4 +5 +6 +``` + +## 3. Iterating with ndenumerate + +- `ndenumerate` allows you to iterate with both the index and the value of each element. +- It gives index and value as output in each iteration + +```python +import numpy as np + +arr = np.array([[1, 2], [3, 4]]) +for index,value in np.ndenumerate(arr): + print(index,value) +``` + +**Output** : + +```python +(0, 0) 1 +(0, 1) 2 +(1, 0) 3 +(1, 1) 4 +``` + +## 4. Iterating with flat + +- The `flat` attribute returns a 1-D iterator over the array. +- + +```python +import numpy as np + +arr = np.array([[1, 2], [3, 4]]) +for element in arr.flat: + print(element) +``` + +**Output** : + +```python +1 +2 +3 +4 +``` + +Understanding the various ways to iterate over NumPy arrays can significantly enhance your data processing efficiency. +Whether you are working with single-dimensional or multi-dimensional arrays, NumPy provides versatile tools to iterate and manipulate array elements effectively. From 7ef8cb226d414c75cb62167aa20d7fa4b78eb051 Mon Sep 17 00:00:00 2001 From: Lingamuneni Santhosh Siddhardha <103999924+Santhosh-Siddhardha@users.noreply.github.com> Date: Tue, 28 May 2024 21:29:29 +0530 Subject: [PATCH 05/10] Delete contrib/pandas/numpy_array_iteration.md Wrong folder --- contrib/pandas/numpy_array_iteration.md | 109 ------------------------ 1 file changed, 109 deletions(-) delete mode 100644 contrib/pandas/numpy_array_iteration.md diff --git a/contrib/pandas/numpy_array_iteration.md b/contrib/pandas/numpy_array_iteration.md deleted file mode 100644 index ac35d95..0000000 --- a/contrib/pandas/numpy_array_iteration.md +++ /dev/null @@ -1,109 +0,0 @@ -# NumPy Array Iteration - -Iterating over arrays in NumPy is a common task when processing data. NumPy provides several ways to iterate over elements of an array efficiently. -Understanding these methods is crucial for performing operations on array elements effectively. - -## 1. Basic Iteration - -- Iterating using basic `for` loop. - -**Single-dimensional array iteration**: - -Iterating over a single-dimensional array is straightforward using a basic `for` loop - -```python -import numpy as np - -arr = np.array([1, 2, 3, 4, 5]) -for i in arr: - print(i) -``` -**Output** : -```python -[ 1 2 3 4 5 ] -``` -**Multi-dimensional array**: - -Iterating over multi-dimensional arrays, each iteration returns a sub-array along the first axis. - -```python -marr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) - -for arr in marr: - print(arr) -``` -**Output** : -```python -[1 2 3] -[4 5 6] -[7 8 9] -``` - -## 2. Iterating with nditer - -- `nditer` is a powerful iterator provided by NumPy for iterating over multi-dimensional arrays. -- In each interation it gives each element. - -```python -import numpy as np - -arr = np.array([[1, 2, 3], [4, 5, 6]]) -for i in np.nditer(arr): - print(i) -``` -**Output** : -```python -1 -2 -3 -4 -5 -6 -``` - -## 3. Iterating with ndenumerate - -- `ndenumerate` allows you to iterate with both the index and the value of each element. -- It gives index and value as output in each iteration - -```python -import numpy as np - -arr = np.array([[1, 2], [3, 4]]) -for index,value in np.ndenumerate(arr): - print(index,value) -``` - -**Output** : - -```python -(0, 0) 1 -(0, 1) 2 -(1, 0) 3 -(1, 1) 4 -``` - -## 4. Iterating with flat - -- The `flat` attribute returns a 1-D iterator over the array. -- - -```python -import numpy as np - -arr = np.array([[1, 2], [3, 4]]) -for element in arr.flat: - print(element) -``` - -**Output** : - -```python -1 -2 -3 -4 -``` - -Understanding the various ways to iterate over NumPy arrays can significantly enhance your data processing efficiency. -Whether you are working with single-dimensional or multi-dimensional arrays, NumPy provides versatile tools to iterate and manipulate array elements effectively. From 866d28dfdd63539e570e5eead81afc2f1c7e9b06 Mon Sep 17 00:00:00 2001 From: Lingamuneni Santhosh Siddhardha <103999924+Santhosh-Siddhardha@users.noreply.github.com> Date: Tue, 28 May 2024 21:30:02 +0530 Subject: [PATCH 06/10] Update index.md Removed unwanted section --- contrib/pandas/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/pandas/index.md b/contrib/pandas/index.md index 9bf59a3..2b3149a 100644 --- a/contrib/pandas/index.md +++ b/contrib/pandas/index.md @@ -7,4 +7,4 @@ - [Excel using Pandas DataFrame](excel_with_pandas.md) - [Importing and Exporting Data in Pandas](import-export.md) - [Handling Missing Values in Pandas](handling-missing-values.md) -- [NumPy Array Iteration](numpy_array_iteration.md) + From 8a2b838e7bd47122c18cb4877399ebc98e559482 Mon Sep 17 00:00:00 2001 From: Lingamuneni Santhosh Siddhardha <103999924+Santhosh-Siddhardha@users.noreply.github.com> Date: Tue, 28 May 2024 21:30:37 +0530 Subject: [PATCH 07/10] Update index.md Added numpy array iteration section --- contrib/numpy/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/numpy/index.md b/contrib/numpy/index.md index b2d459a..5e88e1d 100644 --- a/contrib/numpy/index.md +++ b/contrib/numpy/index.md @@ -8,3 +8,4 @@ - [Loading Arrays from Files](loading_arrays_from_files.md) - [Saving Numpy Arrays into FIles](saving_numpy_arrays_to_files.md) - [Sorting NumPy Arrays](sorting-array.md) +- [NumPy Array Iteration](numpy_array_iteration.md) From 1f4f3abd20eac2ad0c04e8372c2254a12b2e55d6 Mon Sep 17 00:00:00 2001 From: Lingamuneni Santhosh Siddhardha <103999924+Santhosh-Siddhardha@users.noreply.github.com> Date: Tue, 28 May 2024 21:34:59 +0530 Subject: [PATCH 08/10] Update index.md --- contrib/pandas/index.md | 1 - 1 file changed, 1 deletion(-) diff --git a/contrib/pandas/index.md b/contrib/pandas/index.md index 2b3149a..c71c324 100644 --- a/contrib/pandas/index.md +++ b/contrib/pandas/index.md @@ -7,4 +7,3 @@ - [Excel using Pandas DataFrame](excel_with_pandas.md) - [Importing and Exporting Data in Pandas](import-export.md) - [Handling Missing Values in Pandas](handling-missing-values.md) - From 75423bc5ba6e4a698ebc53df6f13af52f4cfc21f Mon Sep 17 00:00:00 2001 From: Ankit Mahato Date: Fri, 31 May 2024 06:14:48 +0530 Subject: [PATCH 09/10] Rename numpy_array_iteration.md to array-iteration.md --- contrib/numpy/{numpy_array_iteration.md => array-iteration.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contrib/numpy/{numpy_array_iteration.md => array-iteration.md} (100%) diff --git a/contrib/numpy/numpy_array_iteration.md b/contrib/numpy/array-iteration.md similarity index 100% rename from contrib/numpy/numpy_array_iteration.md rename to contrib/numpy/array-iteration.md From 3bebec30e0529dac743073495a12ad85cd1e3904 Mon Sep 17 00:00:00 2001 From: Ankit Mahato Date: Fri, 31 May 2024 06:18:47 +0530 Subject: [PATCH 10/10] Update array-iteration.md --- contrib/numpy/array-iteration.md | 35 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/contrib/numpy/array-iteration.md b/contrib/numpy/array-iteration.md index ac35d95..b0a499f 100644 --- a/contrib/numpy/array-iteration.md +++ b/contrib/numpy/array-iteration.md @@ -7,7 +7,7 @@ Understanding these methods is crucial for performing operations on array elemen - Iterating using basic `for` loop. -**Single-dimensional array iteration**: +### Single-dimensional array Iterating over a single-dimensional array is straightforward using a basic `for` loop @@ -18,11 +18,18 @@ arr = np.array([1, 2, 3, 4, 5]) for i in arr: print(i) ``` -**Output** : + +#### Output + ```python -[ 1 2 3 4 5 ] +1 +2 +3 +4 +5 ``` -**Multi-dimensional array**: + +### Multi-dimensional array Iterating over multi-dimensional arrays, each iteration returns a sub-array along the first axis. @@ -32,14 +39,16 @@ marr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) for arr in marr: print(arr) ``` -**Output** : + +#### Output + ```python [1 2 3] [4 5 6] [7 8 9] ``` -## 2. Iterating with nditer +## 2. Iterating with `nditer` - `nditer` is a powerful iterator provided by NumPy for iterating over multi-dimensional arrays. - In each interation it gives each element. @@ -51,7 +60,9 @@ arr = np.array([[1, 2, 3], [4, 5, 6]]) for i in np.nditer(arr): print(i) ``` -**Output** : + +#### Output + ```python 1 2 @@ -61,7 +72,7 @@ for i in np.nditer(arr): 6 ``` -## 3. Iterating with ndenumerate +## 3. Iterating with `ndenumerate` - `ndenumerate` allows you to iterate with both the index and the value of each element. - It gives index and value as output in each iteration @@ -74,7 +85,7 @@ for index,value in np.ndenumerate(arr): print(index,value) ``` -**Output** : +#### Output ```python (0, 0) 1 @@ -86,7 +97,6 @@ for index,value in np.ndenumerate(arr): ## 4. Iterating with flat - The `flat` attribute returns a 1-D iterator over the array. -- ```python import numpy as np @@ -96,7 +106,7 @@ for element in arr.flat: print(element) ``` -**Output** : +#### Output ```python 1 @@ -105,5 +115,6 @@ for element in arr.flat: 4 ``` -Understanding the various ways to iterate over NumPy arrays can significantly enhance your data processing efficiency. +Understanding the various ways to iterate over NumPy arrays can significantly enhance your data processing efficiency. + Whether you are working with single-dimensional or multi-dimensional arrays, NumPy provides versatile tools to iterate and manipulate array elements effectively.