Python NumPy Introduction - Complete Guide
text1. NumPy Kya Hai?
NumPy (Numerical Python) ek popular Python library hai jo high-performance multidimensional arrays aur matrices ke saath numerical computation provide karti hai. Ye scientific computing aur data science ke liye bahut important hai.
2. NumPy Kab Aur Kyun Use Karein?
- Python lists ke comparison me NumPy arrays kaafi faster hote hain.
- Large numerical data efficiently handle karne ke liye optimized algorithms provide karta hai.
- Linear algebra, statistical operations, Fourier transforms jaise features built-in available hain.
- Data science, machine learning, image processing, simulations me extensively use hota hai.
3. NumPy Install Kaise Karein?
pip install numpytext
4. NumPy Import Karna
import numpy as nptext
5. NumPy Arrays Banana
NumPy ka core object hai ndarray
jo homogenous data store karta hai.
import numpy as np 1D array a = np.array() print(a) # [1 2 3 4] print(type(a)) #text2D array (matrix) b = np.array([, ]) print(b) [[1 2 3] [4 5 6]] print(b.shape) # (2, 3) - 2 rows, 3 columns
6. Kuch Common NumPy Functions
import numpy as np print(np.zeros((2, 3))) # 2x3 zero matrix print(np.ones((3, 2))) # 3x2 matrix of ones print(np.eye(3)) # 3x3 identity matrix print(np.arange(5)) # Array [0 1 2 3 4] print(np.linspace(0, 1, 5)) # 5 numbers from 0 to 1 evenly spacedtext
7. Array Operations
NumPy me arithmetic operations element-wise hote hain.
a = np.array() b = np.array() print(a + b) # [5 7 9] print(a * b) # [4 10 18] print(a ** 2) # [1 4 9] print(np.sqrt(a)) # [1. 1.414 1.732]text
8. Array Indexing aur Slicing
a = np.array() print(a) # 10 print(a[1:4]) # [20 30 40] print(a[-1]) # 50 b = np.array([, ]) print(b) # 2 print(b[:, 2]) # [3 6]text
9. Practical Example: Matrix Multiplication
A = np.array([, ]) B = np.array([, ]) C = np.dot(A, B) # Matrix multiplication print(C) [[19 22] [43 50]] text
10. Summary
NumPy Python ke numerical computations ke liye ek powerful library hai jo efficient data processing aur scientific calculations me madad karti hai. Iska core object ndarray aapko multi-dimensional arrays create karne aur operations perform karne deta hai jo Python ke normal lists se kaafi faster aur optimized hote hain. Linear algebra aur statistical functions isko data science me bahut popular banate hain. NumPy seekhna data science ya scientific computing ke liye fundamental step hai.