NumPy (Numerical Python) is the most important library for numerical computing in Python.
It is widely used in:
โ Data Science
โ Machine Learning
โ AI
โ Scientific computing
๐น 1. What is NumPy?
NumPy provides a powerful data structure called NumPy Array. It is faster and more efficient than Python lists for mathematical operations.
Example:
import numpy as np
๐น 2. Creating a NumPy Array
From a List
import numpy as np
arr = np.array([1, 2, 3, 4])
print(arr)
Output:
[1 2 3 4]
๐น 3. Check Array Type
print(type(arr))
Output:
<class 'numpy.ndarray'>
๐น 4. NumPy Array Operations
Addition:
import numpy as np
arr = np.array([1, 2, 3])
print(arr + 2)
Output:
[3 4 5]
Multiplication:
print(arr * 2)
Output:
[2 4 6]
๐น 5. NumPy Built-in Functions
arr = np.array([10, 20, 30, 40])
print(arr.sum())
print(arr.mean())
print(arr.max())
print(arr.min())
Output:
100
25.0
40
10
๐น 6. NumPy Array Shape
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr.shape)
Output:
(2, 3)
Meaning: 2 rows and 3 columns.
๐น 7. Why NumPy is Important?
NumPy is the foundation of data science libraries:
โ Pandas
โ Scikit-Learn
โ TensorFlow
โ PyTorch
All these libraries use NumPy internally.
๐ฏ Today's Goal
โ Install NumPy
โ Create arrays
โ Perform math operations
โ Understand array shape
Double Tap โฅ๏ธ For More