NumPy_Complete_Notes
NumPy_Complete_Notes
What is NumPy?
NumPy (Numerical Python) is a powerful Python library for numerical computations. It provides support for
arrays, matrices, and many mathematical functions.
Installation
Importing NumPy
import numpy as np
Creating Arrays
Array Attributes
- shape: array.shape
- size: array.size
- ndim: array.ndim
- dtype: array.dtype
Array Operations
Element-wise operations:
- Addition: arr1 + arr2
- Multiplication: arr1 * arr2
Mathematical Functions
Common functions:
- np.sum(), np.mean(), np.std(), np.min(), np.max()
- np.sqrt(), np.exp(), np.log(), np.sin()
Reshaping Arrays
- np.unique()
- np.concatenate()
- np.split()
- np.sort()
- np.where(condition, x, y)
Example Program
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print("Shape:", arr.shape)
print("Sum:", np.sum(arr))
print("Mean:", np.mean(arr))