Skip to content

Commit c7f2d11

Browse files
Added Readme for maths operations
1 parent 9fcf915 commit c7f2d11

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import numpy as np
2+
3+
# Creating a 1D NumPy array
4+
array = np.array([20, 30, 40, 50, 60])
5+
6+
# -------------------------
7+
# np.sum()
8+
# Calculates the sum of all elements in the array
9+
print(np.sum(array))
10+
# Output: 200
11+
# Meaning: 20 + 30 + 40 + 50 + 60 = 200
12+
13+
# -------------------------
14+
# np.mean()
15+
# Calculates the average (arithmetic mean) of the array elements
16+
print(np.mean(array))
17+
# Output: 40.0
18+
# Meaning: (Sum of elements) / (Number of elements) → 200/5 = 40.0
19+
20+
# -------------------------
21+
# np.min()
22+
# Finds the smallest (minimum) value in the array
23+
print(np.min(array))
24+
# Output: 20
25+
# Meaning: Among 20, 30, 40, 50, 60 → minimum is 20
26+
27+
# -------------------------
28+
# np.max()
29+
# Finds the largest (maximum) value in the array
30+
print(np.max(array))
31+
# Output: 60
32+
# Meaning: Among 20, 30, 40, 50, 60 → maximum is 60
33+
34+
# -------------------------
35+
# np.std()
36+
# Calculates the standard deviation (spread or dispersion) of the array elements
37+
print(np.std(array))
38+
# Output: 14.142135623730951
39+
# Meaning: How much the numbers differ from the mean (larger std means more spread).
40+
41+
# -------------------------
42+
# np.var()
43+
# Calculates the variance (square of standard deviation)
44+
print(np.var(array))
45+
# Output: 200.0
46+
# Meaning: Variance measures the average degree to which each number is different from the mean.
47+

Numpy maths operatioms/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
📊 NumPy Operators and Aggregation Functions
2+
This repository showcases how to perform mathematical operations and aggregation functions using NumPy arrays. With these basic concepts, you can efficiently work with data and perform complex mathematical tasks.
3+
4+
📘 Table of Contents
5+
1. Introduction
6+
7+
2. Mathematical Operators
8+
9+
3. Aggregation Functions
10+
11+
4. Conclusion
12+
13+
1. Introduction
14+
NumPy is a powerful library in Python used for numerical computing. It allows users to perform vectorized operations and matrix computations with ease. In this guide, we'll explore mathematical operators and aggregation functions available in NumPy.
15+
16+
2. Mathematical Operators
17+
NumPy provides a wide range of mathematical operators that can be applied directly to NumPy arrays.
18+
19+
Common Mathematical Operations:
20+
21+
Operator Description
22+
+ Addition
23+
- Subtraction
24+
* Multiplication
25+
/ Division
26+
** Exponentiation
27+
// Floor Division
28+
% Modulo (Remainder)
29+
These operations are element-wise, which means the operation is applied to each element of the array.
30+
31+
3. Aggregation Functions
32+
NumPy provides several functions to aggregate and summarize data in arrays, such as:
33+
34+
35+
Function Description
36+
np.sum() Sum of all elements
37+
np.mean() Mean (average) of elements
38+
np.min() Minimum value of the array
39+
np.max() Maximum value of the array
40+
np.std() Standard deviation of the elements
41+
np.var() Variance (square of standard deviation)
42+
These functions help to quickly compute summaries and statistics over an array.
43+
44+
4. Conclusion
45+
NumPy simplifies performing mathematical operations and aggregating results on large datasets. With the operators and functions covered in this guide, you'll be able to:
46+
47+
Perform quick element-wise operations on arrays.
48+
49+
Summarize data using powerful aggregation functions.
50+
51+
For more advanced NumPy features, feel free to explore official NumPy documentation.
52+
53+
💡 Key Takeaways:
54+
NumPy allows for efficient mathematical operations on arrays.
55+
56+
Aggregation functions such as np.sum(), np.mean(), etc., provide quick statistical summaries of data.
57+
58+
Element-wise operations and broadcasting enable efficient handling of large datasets.
59+

0 commit comments

Comments
 (0)