From 28d6c597fdaa888d4b0852d5e90a411a82b633d5 Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Sun, 12 May 2024 00:14:42 +0530 Subject: [PATCH 01/20] Updated List of sections --- contrib/numpy/index.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/contrib/numpy/index.md b/contrib/numpy/index.md index 82596a2f..bba14f22 100644 --- a/contrib/numpy/index.md +++ b/contrib/numpy/index.md @@ -1,3 +1,14 @@ # List of sections +* [NumPy](#NumPy) + * [Introduction to Numpy](#introduction-to-numpy) + * [Creating Arrays](#creating-arrays) + * [Array Indexing and Slicing](#arrays-indexing-and-slicing) + * [Operations on Arrays](#operation-on-arrays) + * [Concatenating Arrays](#concatenating-arrays) + * [Reshaping Arrays](#reshaping-arrays) + * [Splitting Arrays](#splitting-arrays) + * [Statistical Operations on Arrays](#statistical-operations-on-arrays) + * [Loading Arrays from Files](#loading-arrays-from-files) + * [Saving NumPy Arrays in Files](#saving-numpy-arrays-in-files) -- [Section title](filename.md) +- [Introduction to Numpy](introduction-to-numpy.md) From 0bb3e5f4f2c1a51529275b7ce0e0d756e2dbc87c Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Sun, 12 May 2024 01:56:28 +0530 Subject: [PATCH 02/20] Updated index.md Added info about how to install NumPy in a system. --- contrib/numpy/index.md | 97 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 83 insertions(+), 14 deletions(-) diff --git a/contrib/numpy/index.md b/contrib/numpy/index.md index bba14f22..98cf425a 100644 --- a/contrib/numpy/index.md +++ b/contrib/numpy/index.md @@ -1,14 +1,83 @@ -# List of sections -* [NumPy](#NumPy) - * [Introduction to Numpy](#introduction-to-numpy) - * [Creating Arrays](#creating-arrays) - * [Array Indexing and Slicing](#arrays-indexing-and-slicing) - * [Operations on Arrays](#operation-on-arrays) - * [Concatenating Arrays](#concatenating-arrays) - * [Reshaping Arrays](#reshaping-arrays) - * [Splitting Arrays](#splitting-arrays) - * [Statistical Operations on Arrays](#statistical-operations-on-arrays) - * [Loading Arrays from Files](#loading-arrays-from-files) - * [Saving NumPy Arrays in Files](#saving-numpy-arrays-in-files) - -- [Introduction to Numpy](introduction-to-numpy.md) +# Installing NumPy + +- [Installing NumPy](installing-numpy.md) + +NumPy is the fundamental package for scientific computing in Python. +NumPy is used for working with arrays. + +The only prerequisite for installing NumPy is Python itself. +# +**Step 1: Check if PIP is Installed** + +Before installing NumPy, it's essential to ensure that PIP (Python Package Installer) is installed on your system. PIP is a package management system used to install and manage Python packages. You can verify if PIP is installed by running a simple command in your terminal or command prompt. + +``` +pip --version +``` + +If PIP is not currently installed on your system, you can install it by visiting the [pypi.org](https://pypi.org/project/pip/) webpage. + +# +**Step 2: Installing PIP** + +**get-pip.py** + +This is a Python script that uses some bootstrapping logic to install pip. + +Open a terminal / command prompt and run: + +**Linux** +``` +python get-pip.py +``` + +**Windows** +``` +py get-pip.py +``` + +**MacOS** +``` +python get-pip.py +``` + +# +**Step 3: Installing NumPy** + +NumPy can be installed either through conda or pip. + +If you use pip, you can install NumPy with: + +``` +pip install numpy +``` + +If you use conda, you can install NumPy from the defaults or conda-forge channels: + +``` +# Best practice, use an environment rather than install in the base env +conda create -n my-env +conda activate my-env +``` + +``` +# If you want to install from conda-forge +conda config --env --add channels conda-forge +``` + +``` +# The actual install command +conda install numpy +``` + +You can find more information about how to install [NumPy](https://numpy.org/install/) on numpy.org. + +# +**Step 4: Check if NumPy is Installed** + +We can utilize the "pip show" command not only to display the version but also to determine whether NumPy is installed on the system. +``` +pip show numpy +``` + + From 111553aee7bc4a6f81f5cfec6d0b34ad513601f2 Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Mon, 13 May 2024 06:47:29 +0530 Subject: [PATCH 03/20] Added installing numpy.md file and updated the index.md --- contrib/numpy/index.md | 82 +----------------------------------------- 1 file changed, 1 insertion(+), 81 deletions(-) diff --git a/contrib/numpy/index.md b/contrib/numpy/index.md index 98cf425a..cf992512 100644 --- a/contrib/numpy/index.md +++ b/contrib/numpy/index.md @@ -1,83 +1,3 @@ # Installing NumPy -- [Installing NumPy](installing-numpy.md) - -NumPy is the fundamental package for scientific computing in Python. -NumPy is used for working with arrays. - -The only prerequisite for installing NumPy is Python itself. -# -**Step 1: Check if PIP is Installed** - -Before installing NumPy, it's essential to ensure that PIP (Python Package Installer) is installed on your system. PIP is a package management system used to install and manage Python packages. You can verify if PIP is installed by running a simple command in your terminal or command prompt. - -``` -pip --version -``` - -If PIP is not currently installed on your system, you can install it by visiting the [pypi.org](https://pypi.org/project/pip/) webpage. - -# -**Step 2: Installing PIP** - -**get-pip.py** - -This is a Python script that uses some bootstrapping logic to install pip. - -Open a terminal / command prompt and run: - -**Linux** -``` -python get-pip.py -``` - -**Windows** -``` -py get-pip.py -``` - -**MacOS** -``` -python get-pip.py -``` - -# -**Step 3: Installing NumPy** - -NumPy can be installed either through conda or pip. - -If you use pip, you can install NumPy with: - -``` -pip install numpy -``` - -If you use conda, you can install NumPy from the defaults or conda-forge channels: - -``` -# Best practice, use an environment rather than install in the base env -conda create -n my-env -conda activate my-env -``` - -``` -# If you want to install from conda-forge -conda config --env --add channels conda-forge -``` - -``` -# The actual install command -conda install numpy -``` - -You can find more information about how to install [NumPy](https://numpy.org/install/) on numpy.org. - -# -**Step 4: Check if NumPy is Installed** - -We can utilize the "pip show" command not only to display the version but also to determine whether NumPy is installed on the system. -``` -pip show numpy -``` - - +- [Installing NumPy](installing numpy.md) From f549e34b5dd6aafb5f070121e7ada90edadfa911 Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Mon, 13 May 2024 06:49:07 +0530 Subject: [PATCH 04/20] Added installing-numpy.md file and updated the index.md --- contrib/numpy/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/numpy/index.md b/contrib/numpy/index.md index cf992512..6377e236 100644 --- a/contrib/numpy/index.md +++ b/contrib/numpy/index.md @@ -1,3 +1,3 @@ # Installing NumPy -- [Installing NumPy](installing numpy.md) +- [Installing NumPy](installing-numpy.md) From 705e55e3e7f5d58458acded41586d3e8e283e7cc Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Mon, 13 May 2024 06:53:33 +0530 Subject: [PATCH 05/20] Create installing-numpy.md for installation --- contrib/numpy/installing-numpy.md | 79 +++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 contrib/numpy/installing-numpy.md diff --git a/contrib/numpy/installing-numpy.md b/contrib/numpy/installing-numpy.md new file mode 100644 index 00000000..c9fae64a --- /dev/null +++ b/contrib/numpy/installing-numpy.md @@ -0,0 +1,79 @@ +# Installing NumPy + +NumPy is the fundamental package for scientific computing in Python. +NumPy is used for working with arrays. + +The only prerequisite for installing NumPy is Python itself. +# +**Step 1: Check if PIP is Installed** + +Before installing NumPy, it's essential to ensure that PIP (Python Package Installer) is installed on your system. PIP is a package management system used to install and manage Python packages. You can verify if PIP is installed by running a simple command in your terminal or command prompt. + +``` +pip --version +``` + +If PIP is not currently installed on your system, you can install it by visiting the [pypi.org](https://pypi.org/project/pip/) webpage. + +# +**Step 2: Installing PIP** + +**get-pip.py** + +This is a Python script that uses some bootstrapping logic to install pip. + +Open a terminal / command prompt and run: + +**Linux** +``` +python get-pip.py +``` + +**Windows** +``` +py get-pip.py +``` + +**MacOS** +``` +python get-pip.py +``` + +# +**Step 3: Installing NumPy** + +NumPy can be installed either through conda or pip. + +If you use pip, you can install NumPy with: + +``` +pip install numpy +``` + +If you use conda, you can install NumPy from the defaults or conda-forge channels: + +``` +# Best practice, use an environment rather than install in the base env +conda create -n my-env +conda activate my-env +``` + +``` +# If you want to install from conda-forge +conda config --env --add channels conda-forge +``` + +``` +# The actual install command +conda install numpy +``` + +You can find more information about how to install [NumPy](https://numpy.org/install/) on numpy.org. + +# +**Step 4: Check if NumPy is Installed** + +We can utilize the "pip show" command not only to display the version but also to determine whether NumPy is installed on the system. +``` +pip show numpy +``` From 18c9837a1d74fe6de1310f9b02248f89a983fa98 Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Wed, 15 May 2024 15:09:26 +0530 Subject: [PATCH 06/20] Update index.md Added operations-on-arrays.md --- contrib/numpy/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/numpy/index.md b/contrib/numpy/index.md index 6377e236..e39f4850 100644 --- a/contrib/numpy/index.md +++ b/contrib/numpy/index.md @@ -1,3 +1,4 @@ -# Installing NumPy +# NumPy - [Installing NumPy](installing-numpy.md) +- [Operations on Arrays in NumPy](operations-on-arrays.md) From 7c84dcee772d851af5b648ea1bc6343d21a87af3 Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Wed, 15 May 2024 20:04:16 +0530 Subject: [PATCH 07/20] Create operations-on-arrays.md --- contrib/numpy/operations-on-arrays.md | 246 ++++++++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 contrib/numpy/operations-on-arrays.md diff --git a/contrib/numpy/operations-on-arrays.md b/contrib/numpy/operations-on-arrays.md new file mode 100644 index 00000000..5c2be798 --- /dev/null +++ b/contrib/numpy/operations-on-arrays.md @@ -0,0 +1,246 @@ +# Operations on Arrays + +## NumPy Arithmetic Operations + +
+ +NumPy offers a broad array of operations for arrays, including arithmetic functions. + +The arithmetic operations in NumPy are popular for their simplicity and efficiency in handling array calculations. + +Here is a list of different arithmetic operations along with their corresponding operators: + +| Element-wise Operation | Operator | +|------------------------|:--------:| +| Addition | + | +| Subtraction | - | +| Multiplication | * | +| Division | / | +| Exponentiation | ** | +| Modulus | % | + +# + +### Code Initialization + +```python +import numpy as np + +array_1 = np.array([9, 10, 11, 12]) +array_2 = np.array([1, 3, 5, 7]) +``` + +### Addition +```python +# Utilizing the + operator +result_1 = array_1 + array_2 +print("Utilizing the + operator:", result_1) +``` + +Output: +``` +Utilizing the + operator: [10 13 16 19] +``` + +### Subtraction +```python +# Utilizing the - operator +result_1 = array_1 - array_2 +print("Utilizing the - operator:", result_1) +``` + +Output: +``` +Utilizing the - operator: [8 7 6 5] +``` + +### Multiplication +```python +# Utilizing the * operator +result_1 = array_1 * array_2 +print("Utilizing the * operator:", result_1) +``` + +Output: +``` +Utilizing the * operator: [9 30 55 84] +``` + +### Division +```python +# Utilizing the / operator +result_1 = array_1 / array_2 +print("Utilizing the / operator:", result_1) +``` + +Output: +``` +Utilizing the / operator: [9. 3.33333333 2.2 1.71428571] +``` + +### Exponentiation +```python +# Utilizing the ** operator +result_1 = array_1 ** array_2 +print("Utilizing the ** operator:", result_1) +``` + +Output: +``` +Utilizing the ** operator: [9 1000 161051 35831808] +``` + +### Modulus +```python +# Utilizing the % operator +result_1 = array_1 % array_2 +print("Utilizing the % operator:", result_1) +``` + +Output: +``` +Utilizing the ** operator: [0 1 1 5] +``` + +
+ +## NumPy Comparision Operations + +
+ +NumPy provides various comparison operators that can compare elements across multiple NumPy arrays. + +| Operator | Description | +|:--------:|-------------------------------------------------------------------------------------------------------------------------------| +| < | Evaluates to True if the element in the first array is less than the corresponding element in the second array | +| <= | Evaluates to True if the element in the first array is less than or equal to the corresponding element in the second array | +| > | Evaluates to True if the element in the first array is greater than the corresponding element in the second array | +| >= | Evaluates to True if the element in the first array is greater than or equal to the corresponding element in the second array | +| == | Evaluates to True if the element in the first array is equal to the corresponding element in the second array | +| != | Evaluates to True if the element in the first array is not equal to the corresponding element in the second array | + +# + +### Code Initialization + +```python +import numpy as np + +array_1 = np.array([12,15,20]) +array_2 = np.array([20,15,12]) +``` + +#### less than operator +```python +result_1 = array_1 < array_2 +print("array_1 < array_2:",result_1) +``` +Output: +``` +array_1 < array_2 : [True False False] +``` + +#### less than or equal to operator +```python +result_1 = array_1 <= array_2 +print("array_1 <= array_2:",result_1) +``` +Output: +``` +array_1 <= array_2: [True True False] +``` + +#### greater than operator +```python +result_2 = array_1 > array_2 +print("array_1 > array_2:",result_2) +``` +Output: +``` +array_1 > array_2 : [False False True] +``` + +#### greater than or equal to operator +```python +result_2 = array_1 >= array_2 +print("array_1 >= array_2:",result_2) +``` +Output: +``` +array_1 >= array_2: [False True True] +``` + +#### equal to operator +```python +result_3 = array_1 == array_2 +print("array_1 == array_2:",result_3) +``` +Output: +``` +array_1 == array_2: [False True False] +``` + +#### not equal to operator +```python +result_3 = array_1 != array_2 +print("array_1 != array_2:",result_3) +``` +Output: +``` +array_1 != array_2: [True False True] +``` + +
+ +## NumPy Logical Operations + +
+ +Logical operators perform Boolean algebra. A branch of algebra that deals with True and False statements. + +| Operator | Description | +|---------------|-----------------------------------------------------| +| logical_and | Evaluates the element-wise truth value of x1 AND x2 | +| logical_or | Evaluates the element-wise truth value of x1 OR x2 | +| logical_not | Evaluates the element-wise truth value of NOT x | + + +It illustrates the logical operations of AND, OR, and NOT using np.logical_and(), np.logical_or(), and np.logical_not() functions, respectively. + +# + +### Code Initialization + +```python +import numpy as np + +array_1 = np.array([True, False, True]) +array_2 = np.array([False, False, True]) +``` + +#### Logical AND +```python +print(np.logical_and(array_1, array_2)) +``` +Output: +``` +[False False True] +``` + +#### Logical OR +```python +print(np.logical_or(array_1, array_2)) +``` +Output: +``` +[True False True] +``` + +#### Logical NOT +```python +print(np.logical_not(array_1)) +``` +Output: +``` +[False True False] +``` From 9e9e17f51508791dde80c9826497a1a17ae3a96d Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Wed, 15 May 2024 20:04:35 +0530 Subject: [PATCH 08/20] Update index.md --- contrib/numpy/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/numpy/index.md b/contrib/numpy/index.md index e39f4850..757407a6 100644 --- a/contrib/numpy/index.md +++ b/contrib/numpy/index.md @@ -1,4 +1,4 @@ -# NumPy +# List of sections - [Installing NumPy](installing-numpy.md) - [Operations on Arrays in NumPy](operations-on-arrays.md) From 57f73ec029a64917fb6bb83a678ef075509dfeb6 Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Wed, 15 May 2024 20:10:46 +0530 Subject: [PATCH 09/20] Update index.md --- contrib/numpy/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/numpy/index.md b/contrib/numpy/index.md index 757407a6..18f10b20 100644 --- a/contrib/numpy/index.md +++ b/contrib/numpy/index.md @@ -1,4 +1,4 @@ # List of sections -- [Installing NumPy](installing-numpy.md) -- [Operations on Arrays in NumPy](operations-on-arrays.md) +- [Installing NumPy](installing_numpy.md) +- [Operations on Arrays in NumPy](operations_on_arrays.md) From 5a23eb9ab04c549503b39c99fef19ebb0fae770b Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Wed, 15 May 2024 20:11:45 +0530 Subject: [PATCH 10/20] Rename installing-numpy.md to installing_numpy.md --- contrib/numpy/{installing-numpy.md => installing_numpy.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contrib/numpy/{installing-numpy.md => installing_numpy.md} (100%) diff --git a/contrib/numpy/installing-numpy.md b/contrib/numpy/installing_numpy.md similarity index 100% rename from contrib/numpy/installing-numpy.md rename to contrib/numpy/installing_numpy.md From 7477daf106d0b269111b32fa634409bf16adee54 Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Wed, 15 May 2024 20:12:07 +0530 Subject: [PATCH 11/20] Rename operations-on-arrays.md to operations_on_arrays.md --- .../numpy/{operations-on-arrays.md => operations_on_arrays.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contrib/numpy/{operations-on-arrays.md => operations_on_arrays.md} (100%) diff --git a/contrib/numpy/operations-on-arrays.md b/contrib/numpy/operations_on_arrays.md similarity index 100% rename from contrib/numpy/operations-on-arrays.md rename to contrib/numpy/operations_on_arrays.md From 23acb72abe0fe19a823152d5212a143c10b6491f Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Wed, 15 May 2024 20:13:26 +0530 Subject: [PATCH 12/20] Update installing_numpy.md --- contrib/numpy/installing_numpy.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/contrib/numpy/installing_numpy.md b/contrib/numpy/installing_numpy.md index c9fae64a..7339e8cf 100644 --- a/contrib/numpy/installing_numpy.md +++ b/contrib/numpy/installing_numpy.md @@ -9,13 +9,14 @@ The only prerequisite for installing NumPy is Python itself. Before installing NumPy, it's essential to ensure that PIP (Python Package Installer) is installed on your system. PIP is a package management system used to install and manage Python packages. You can verify if PIP is installed by running a simple command in your terminal or command prompt. -``` +```bash pip --version ``` If PIP is not currently installed on your system, you can install it by visiting the [pypi.org](https://pypi.org/project/pip/) webpage. # + **Step 2: Installing PIP** **get-pip.py** @@ -25,28 +26,29 @@ This is a Python script that uses some bootstrapping logic to install pip. Open a terminal / command prompt and run: **Linux** -``` +```bash python get-pip.py ``` **Windows** -``` +```bash py get-pip.py ``` **MacOS** -``` +```bash python get-pip.py ``` # + **Step 3: Installing NumPy** NumPy can be installed either through conda or pip. If you use pip, you can install NumPy with: -``` +```bash pip install numpy ``` @@ -71,9 +73,10 @@ conda install numpy You can find more information about how to install [NumPy](https://numpy.org/install/) on numpy.org. # + **Step 4: Check if NumPy is Installed** We can utilize the "pip show" command not only to display the version but also to determine whether NumPy is installed on the system. -``` +```bash pip show numpy ``` From 72017904792268ed66c787b2ced2b76e004f8130 Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Sun, 19 May 2024 18:34:54 +0530 Subject: [PATCH 13/20] Update index.md --- contrib/numpy/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/numpy/index.md b/contrib/numpy/index.md index 18f10b20..757407a6 100644 --- a/contrib/numpy/index.md +++ b/contrib/numpy/index.md @@ -1,4 +1,4 @@ # List of sections -- [Installing NumPy](installing_numpy.md) -- [Operations on Arrays in NumPy](operations_on_arrays.md) +- [Installing NumPy](installing-numpy.md) +- [Operations on Arrays in NumPy](operations-on-arrays.md) From 6e317c6016ae4bb71de80c0c1d5e2da61f952a1a Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Sun, 19 May 2024 18:35:23 +0530 Subject: [PATCH 14/20] Rename installing_numpy.md to installing-numpy.md --- contrib/numpy/{installing_numpy.md => installing-numpy.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contrib/numpy/{installing_numpy.md => installing-numpy.md} (100%) diff --git a/contrib/numpy/installing_numpy.md b/contrib/numpy/installing-numpy.md similarity index 100% rename from contrib/numpy/installing_numpy.md rename to contrib/numpy/installing-numpy.md From 4f0ab2e4d690d747f42e40f6fcbf5f43f87c15b9 Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Sun, 19 May 2024 18:35:57 +0530 Subject: [PATCH 15/20] Rename operations_on_arrays.md to operations-on-arrays.md --- .../numpy/{operations_on_arrays.md => operations-on-arrays.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contrib/numpy/{operations_on_arrays.md => operations-on-arrays.md} (100%) diff --git a/contrib/numpy/operations_on_arrays.md b/contrib/numpy/operations-on-arrays.md similarity index 100% rename from contrib/numpy/operations_on_arrays.md rename to contrib/numpy/operations-on-arrays.md From 3e96184fe258d12e68d0ab129f88eba9ff09f616 Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Mon, 20 May 2024 21:04:32 +0530 Subject: [PATCH 16/20] Update operations-on-arrays.md --- contrib/numpy/operations-on-arrays.md | 207 +++++++++++++++----------- 1 file changed, 121 insertions(+), 86 deletions(-) diff --git a/contrib/numpy/operations-on-arrays.md b/contrib/numpy/operations-on-arrays.md index 5c2be798..16b35c58 100644 --- a/contrib/numpy/operations-on-arrays.md +++ b/contrib/numpy/operations-on-arrays.md @@ -2,102 +2,114 @@ ## NumPy Arithmetic Operations -
- NumPy offers a broad array of operations for arrays, including arithmetic functions. The arithmetic operations in NumPy are popular for their simplicity and efficiency in handling array calculations. -Here is a list of different arithmetic operations along with their corresponding operators: - -| Element-wise Operation | Operator | -|------------------------|:--------:| -| Addition | + | -| Subtraction | - | -| Multiplication | * | -| Division | / | -| Exponentiation | ** | -| Modulus | % | +**Addition** -# - -### Code Initialization +we can use the `+` operator to perform element-wise addition between two or more NumPy arrays. +**Code** ```python import numpy as np - array_1 = np.array([9, 10, 11, 12]) array_2 = np.array([1, 3, 5, 7]) -``` - -### Addition -```python -# Utilizing the + operator result_1 = array_1 + array_2 print("Utilizing the + operator:", result_1) ``` -Output: +**Output:** ``` Utilizing the + operator: [10 13 16 19] ``` -### Subtraction +**Subtraction** + +we can use the `-` operator to perform element-wise subtraction between two or more NumPy arrays. + +**Code** ```python -# Utilizing the - operator +import numpy as np +array_1 = np.array([9, 10, 11, 12]) +array_2 = np.array([1, 3, 5, 7]) result_1 = array_1 - array_2 print("Utilizing the - operator:", result_1) ``` -Output: +**Output:** ``` Utilizing the - operator: [8 7 6 5] ``` -### Multiplication +**Multiplication** + +we can use the `*` operator to perform element-wise multiplication between two or more NumPy arrays. + +**Code** ```python -# Utilizing the * operator +import numpy as np +array_1 = np.array([9, 10, 11, 12]) +array_2 = np.array([1, 3, 5, 7]) result_1 = array_1 * array_2 print("Utilizing the * operator:", result_1) ``` -Output: +**Output:** ``` Utilizing the * operator: [9 30 55 84] ``` -### Division +**Division** + +we can use the `/` operator to perform element-wise division between two or more NumPy arrays. + +**Code** ```python -# Utilizing the / operator +import numpy as np +array_1 = np.array([9, 10, 11, 12]) +array_2 = np.array([1, 3, 5, 7]) result_1 = array_1 / array_2 print("Utilizing the / operator:", result_1) ``` -Output: +**Output:** ``` Utilizing the / operator: [9. 3.33333333 2.2 1.71428571] ``` -### Exponentiation +**Exponentiation** + +we can use the `**` operator to perform element-wise exponentiation between two or more NumPy arrays. + +**Code** ```python -# Utilizing the ** operator +import numpy as np +array_1 = np.array([9, 10, 11, 12]) +array_2 = np.array([1, 3, 5, 7]) result_1 = array_1 ** array_2 print("Utilizing the ** operator:", result_1) ``` -Output: +**Output:** ``` Utilizing the ** operator: [9 1000 161051 35831808] ``` -### Modulus +**Modulus** + +We can use the `%` operator to perform element-wise modulus operations between two or more NumPy arrays. + +**Code** ```python -# Utilizing the % operator +import numpy as np +array_1 = np.array([9, 10, 11, 12]) +array_2 = np.array([1, 3, 5, 7]) result_1 = array_1 % array_2 print("Utilizing the % operator:", result_1) ``` -Output: +**Output:** ``` Utilizing the ** operator: [0 1 1 5] ``` @@ -110,82 +122,104 @@ Utilizing the ** operator: [0 1 1 5] NumPy provides various comparison operators that can compare elements across multiple NumPy arrays. -| Operator | Description | -|:--------:|-------------------------------------------------------------------------------------------------------------------------------| -| < | Evaluates to True if the element in the first array is less than the corresponding element in the second array | -| <= | Evaluates to True if the element in the first array is less than or equal to the corresponding element in the second array | -| > | Evaluates to True if the element in the first array is greater than the corresponding element in the second array | -| >= | Evaluates to True if the element in the first array is greater than or equal to the corresponding element in the second array | -| == | Evaluates to True if the element in the first array is equal to the corresponding element in the second array | -| != | Evaluates to True if the element in the first array is not equal to the corresponding element in the second array | - -# +**less than operator** -### Code Initialization +The `<` operator returns `True` if the value of operand on left is less than the value of operand on right. +**Code** ```python import numpy as np - array_1 = np.array([12,15,20]) array_2 = np.array([20,15,12]) -``` - -#### less than operator -```python result_1 = array_1 < array_2 print("array_1 < array_2:",result_1) ``` -Output: +**Output:** ``` array_1 < array_2 : [True False False] ``` -#### less than or equal to operator +**less than or equal to operator** + +The `<=` operator returns `True` if the value of operand on left is lesser than or equal to the value of operand on right. + +**Code** ```python +import numpy as np +array_1 = np.array([12,15,20]) +array_2 = np.array([20,15,12]) result_1 = array_1 <= array_2 print("array_1 <= array_2:",result_1) ``` -Output: +**Output:** ``` array_1 <= array_2: [True True False] ``` -#### greater than operator +**greater than operator** + +The `>` operator returns `True` if the value of operand on left is greater than the value of operand on right. + +**Code** ```python +import numpy as np +array_1 = np.array([12,15,20]) +array_2 = np.array([20,15,12]) result_2 = array_1 > array_2 print("array_1 > array_2:",result_2) ``` -Output: +**Output:** ``` array_1 > array_2 : [False False True] ``` -#### greater than or equal to operator +**greater than or equal to operator** + +The `>=` operator returns `True` if the value of operand on left is greater than or equal to the value of operand on right. + +**Code** ```python +import numpy as np +array_1 = np.array([12,15,20]) +array_2 = np.array([20,15,12]) result_2 = array_1 >= array_2 print("array_1 >= array_2:",result_2) ``` -Output: +**Output:** ``` array_1 >= array_2: [False True True] ``` -#### equal to operator +**equal to operator** + +The `==` operator returns `True` if the value of operand on left is same as the value of operand on right. + +**Code** ```python +import numpy as np +array_1 = np.array([12,15,20]) +array_2 = np.array([20,15,12]) result_3 = array_1 == array_2 print("array_1 == array_2:",result_3) ``` -Output: +**Output:** ``` array_1 == array_2: [False True False] ``` -#### not equal to operator +**not equal to operator** + +The `!=` operator returns `True` if the value of operand on left is not equal to the value of operand on right. + +**Code** ```python +import numpy as np +array_1 = np.array([12,15,20]) +array_2 = np.array([20,15,12]) result_3 = array_1 != array_2 print("array_1 != array_2:",result_3) ``` -Output: +**Output:** ``` array_1 != array_2: [True False True] ``` @@ -194,53 +228,54 @@ array_1 != array_2: [True False True] ## NumPy Logical Operations -
- -Logical operators perform Boolean algebra. A branch of algebra that deals with True and False statements. - -| Operator | Description | -|---------------|-----------------------------------------------------| -| logical_and | Evaluates the element-wise truth value of x1 AND x2 | -| logical_or | Evaluates the element-wise truth value of x1 OR x2 | -| logical_not | Evaluates the element-wise truth value of NOT x | - +Logical operators perform Boolean algebra. A branch of algebra that deals with `True` and `False` statements. It illustrates the logical operations of AND, OR, and NOT using np.logical_and(), np.logical_or(), and np.logical_not() functions, respectively. -# +**Logical AND** -### Code Initialization +Evaluates the element-wise truth value of `array_1` AND `array_2` +**Code** ```python import numpy as np - array_1 = np.array([True, False, True]) array_2 = np.array([False, False, True]) -``` - -#### Logical AND -```python print(np.logical_and(array_1, array_2)) ``` -Output: +**Output:** ``` [False False True] ``` -#### Logical OR +**Logical OR** + +Evaluates the element-wise truth value of `array_1` OR `array_2` + +**Code** ```python +import numpy as np +array_1 = np.array([True, False, True]) +array_2 = np.array([False, False, True]) print(np.logical_or(array_1, array_2)) ``` -Output: +**Output:** ``` [True False True] ``` -#### Logical NOT +**Logical NOT** + +Evaluates the element-wise truth value of `array_1` NOT `array_2` + +**Code** ```python +import numpy as np +array_1 = np.array([True, False, True]) +array_2 = np.array([False, False, True]) print(np.logical_not(array_1)) ``` -Output: +**Output:** ``` [False True False] ``` From a052aed31f31344a3486840326a65f7c0bdeaec5 Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Mon, 20 May 2024 21:06:15 +0530 Subject: [PATCH 17/20] Update operations-on-arrays.md --- contrib/numpy/operations-on-arrays.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/numpy/operations-on-arrays.md b/contrib/numpy/operations-on-arrays.md index 16b35c58..e3966d27 100644 --- a/contrib/numpy/operations-on-arrays.md +++ b/contrib/numpy/operations-on-arrays.md @@ -111,7 +111,7 @@ print("Utilizing the % operator:", result_1) **Output:** ``` -Utilizing the ** operator: [0 1 1 5] +Utilizing the % operator: [0 1 1 5] ```
From 8d64b3d3becca456f71e64cb6c7e091926c186c2 Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Mon, 20 May 2024 21:31:12 +0530 Subject: [PATCH 18/20] Revert "Update operations-on-arrays.md" --- contrib/numpy/operations-on-arrays.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/numpy/operations-on-arrays.md b/contrib/numpy/operations-on-arrays.md index e3966d27..16b35c58 100644 --- a/contrib/numpy/operations-on-arrays.md +++ b/contrib/numpy/operations-on-arrays.md @@ -111,7 +111,7 @@ print("Utilizing the % operator:", result_1) **Output:** ``` -Utilizing the % operator: [0 1 1 5] +Utilizing the ** operator: [0 1 1 5] ```
From c3cbcb7c18498c8031b6bb21448af4555c25c316 Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Mon, 20 May 2024 21:40:01 +0530 Subject: [PATCH 19/20] Delete contrib/numpy/installing-numpy.md --- contrib/numpy/installing-numpy.md | 82 ------------------------------- 1 file changed, 82 deletions(-) delete mode 100644 contrib/numpy/installing-numpy.md diff --git a/contrib/numpy/installing-numpy.md b/contrib/numpy/installing-numpy.md deleted file mode 100644 index 7339e8cf..00000000 --- a/contrib/numpy/installing-numpy.md +++ /dev/null @@ -1,82 +0,0 @@ -# Installing NumPy - -NumPy is the fundamental package for scientific computing in Python. -NumPy is used for working with arrays. - -The only prerequisite for installing NumPy is Python itself. -# -**Step 1: Check if PIP is Installed** - -Before installing NumPy, it's essential to ensure that PIP (Python Package Installer) is installed on your system. PIP is a package management system used to install and manage Python packages. You can verify if PIP is installed by running a simple command in your terminal or command prompt. - -```bash -pip --version -``` - -If PIP is not currently installed on your system, you can install it by visiting the [pypi.org](https://pypi.org/project/pip/) webpage. - -# - -**Step 2: Installing PIP** - -**get-pip.py** - -This is a Python script that uses some bootstrapping logic to install pip. - -Open a terminal / command prompt and run: - -**Linux** -```bash -python get-pip.py -``` - -**Windows** -```bash -py get-pip.py -``` - -**MacOS** -```bash -python get-pip.py -``` - -# - -**Step 3: Installing NumPy** - -NumPy can be installed either through conda or pip. - -If you use pip, you can install NumPy with: - -```bash -pip install numpy -``` - -If you use conda, you can install NumPy from the defaults or conda-forge channels: - -``` -# Best practice, use an environment rather than install in the base env -conda create -n my-env -conda activate my-env -``` - -``` -# If you want to install from conda-forge -conda config --env --add channels conda-forge -``` - -``` -# The actual install command -conda install numpy -``` - -You can find more information about how to install [NumPy](https://numpy.org/install/) on numpy.org. - -# - -**Step 4: Check if NumPy is Installed** - -We can utilize the "pip show" command not only to display the version but also to determine whether NumPy is installed on the system. -```bash -pip show numpy -``` From f5a03860b613670b28e0af289c277241fa60439a Mon Sep 17 00:00:00 2001 From: Yodha Sudarsi <101962069+Yodha-Sudarsi@users.noreply.github.com> Date: Tue, 21 May 2024 10:11:56 +0530 Subject: [PATCH 20/20] Update operations-on-arrays.md --- contrib/numpy/operations-on-arrays.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/numpy/operations-on-arrays.md b/contrib/numpy/operations-on-arrays.md index 16b35c58..e3966d27 100644 --- a/contrib/numpy/operations-on-arrays.md +++ b/contrib/numpy/operations-on-arrays.md @@ -111,7 +111,7 @@ print("Utilizing the % operator:", result_1) **Output:** ``` -Utilizing the ** operator: [0 1 1 5] +Utilizing the % operator: [0 1 1 5] ```