Skip to content

Added installing-numpy.md file and updated the index.md #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contrib/numpy/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# List of sections

- [Section title](filename.md)
- [Installing NumPy](installing_numpy.md)
- [Operations on Arrays in NumPy](operations_on_arrays.md)
82 changes: 82 additions & 0 deletions contrib/numpy/installing_numpy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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
```
246 changes: 246 additions & 0 deletions contrib/numpy/operations_on_arrays.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
# Operations on Arrays

## NumPy Arithmetic Operations

<br>

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]
```

<br>

## NumPy Comparision Operations

<br>

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]
```

<br>

## NumPy Logical Operations

<br>

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]
```