Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
28d6c59
Updated List of sections
Yodha-Sudarsi May 11, 2024
0bb3e5f
Updated index.md
Yodha-Sudarsi May 11, 2024
111553a
Added installing numpy.md file and updated the index.md
Yodha-Sudarsi May 13, 2024
f549e34
Added installing-numpy.md file and updated the index.md
Yodha-Sudarsi May 13, 2024
705e55e
Create installing-numpy.md for installation
Yodha-Sudarsi May 13, 2024
4cc563d
Merge branch 'animator:main' into main
Yodha-Sudarsi May 15, 2024
18c9837
Update index.md
Yodha-Sudarsi May 15, 2024
7c84dce
Create operations-on-arrays.md
Yodha-Sudarsi May 15, 2024
9e9e17f
Update index.md
Yodha-Sudarsi May 15, 2024
57f73ec
Update index.md
Yodha-Sudarsi May 15, 2024
5a23eb9
Rename installing-numpy.md to installing_numpy.md
Yodha-Sudarsi May 15, 2024
7477daf
Rename operations-on-arrays.md to operations_on_arrays.md
Yodha-Sudarsi May 15, 2024
23acb72
Update installing_numpy.md
Yodha-Sudarsi May 15, 2024
7201790
Update index.md
Yodha-Sudarsi May 19, 2024
6e317c6
Rename installing_numpy.md to installing-numpy.md
Yodha-Sudarsi May 19, 2024
4f0ab2e
Rename operations_on_arrays.md to operations-on-arrays.md
Yodha-Sudarsi May 19, 2024
dfc8c17
Merge branch 'animator:main' into main
Yodha-Sudarsi May 20, 2024
3e96184
Update operations-on-arrays.md
Yodha-Sudarsi May 20, 2024
a052aed
Update operations-on-arrays.md
Yodha-Sudarsi May 20, 2024
096f7d9
Merge pull request #1 from Yodha-Sudarsi/operation-on-arrays
Yodha-Sudarsi May 20, 2024
8d64b3d
Revert "Update operations-on-arrays.md"
Yodha-Sudarsi May 20, 2024
b33fe5c
Merge pull request #2 from Yodha-Sudarsi/revert-1-operation-on-arrays
Yodha-Sudarsi May 20, 2024
c3cbcb7
Delete contrib/numpy/installing-numpy.md
Yodha-Sudarsi May 20, 2024
f5a0386
Update operations-on-arrays.md
Yodha-Sudarsi May 21, 2024
d71bc82
Merge branch 'main' into operation-on-numpy
animator May 23, 2024
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
1 change: 1 addition & 0 deletions contrib/numpy/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- [Installing NumPy](installing-numpy.md)
- [Introduction](introduction.md)
- [NumPy Data Types](datatypes.md)
- [Operations on Arrays in NumPy](operations-on-arrays.md)
281 changes: 281 additions & 0 deletions contrib/numpy/operations-on-arrays.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
# 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.

**Addition**

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])
result_1 = array_1 + array_2
print("Utilizing the + operator:", result_1)
```

**Output:**
```
Utilizing the + operator: [10 13 16 19]
```

**Subtraction**

we can use the `-` operator to perform element-wise subtraction 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])
result_1 = array_1 - array_2
print("Utilizing the - operator:", result_1)
```

**Output:**
```
Utilizing the - operator: [8 7 6 5]
```

**Multiplication**

we can use the `*` operator to perform element-wise multiplication 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])
result_1 = array_1 * array_2
print("Utilizing the * operator:", result_1)
```

**Output:**
```
Utilizing the * operator: [9 30 55 84]
```

**Division**

we can use the `/` operator to perform element-wise division 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])
result_1 = array_1 / array_2
print("Utilizing the / operator:", result_1)
```

**Output:**
```
Utilizing the / operator: [9. 3.33333333 2.2 1.71428571]
```

**Exponentiation**

we can use the `**` operator to perform element-wise exponentiation 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])
result_1 = array_1 ** array_2
print("Utilizing the ** operator:", result_1)
```

**Output:**
```
Utilizing the ** operator: [9 1000 161051 35831808]
```

**Modulus**

We can use the `%` operator to perform element-wise modulus operations 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])
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.

**less than operator**

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])
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**

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:**
```
array_1 <= array_2: [True True False]
```

**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:**
```
array_1 > array_2 : [False False True]
```

**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:**
```
array_1 >= array_2: [False True True]
```

**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:**
```
array_1 == array_2: [False True False]
```

**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:**
```
array_1 != array_2: [True False True]
```

<br>

## NumPy Logical Operations

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**

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])
print(np.logical_and(array_1, array_2))
```
**Output:**
```
[False False True]
```

**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:**
```
[True False True]
```

**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:**
```
[False True False]
```