Numpy
What is NumPy?
Key Features of NumPy:
Installing NumPy:
pip install numpy
Creating NumPy Arrays:
import numpy as np
arr = np.array([1, 2, 3, 4])
. 2D Array (Matrix):
arr_2d = np.array([[1, 2, 3], [4, 5, 6]])
Array with Zeros:
zeros = np.zeros((3, 3)) # 3x3 array of zeros
Array with Ones:
ones = np.ones((2, 3)) # 2x3 array of ones
Array with Range:
range_arr = np.arange(10) # 0 to 9
5. Array Operations:
arr = np.array([1, 2, 3])
result = arr * 2 # Output: [2, 4, 6]
Mathematical Functions:
np.sqrt(arr) # Square root of each element
np.exp(arr) # Exponential of each element
np.log(arr) # Natural log of each element
6. Array Indexing and Slicing:
Indexing:
arr = np.array([10, 20, 30, 40])
arr[1] # Output: 20
Slicing:
arr[1:3] # Output: [20, 30]
arr[:3] # Output: [10, 20, 30]
7. Reshaping Arrays:
arr = np.array([1, 2, 3, 4, 5, 6])
reshaped = arr.reshape(2, 3) # 2x3 matrix
8. Broadcasting:
arr = np.array([1, 2, 3])
matrix = np.array([[1], [2], [3]])
result = arr + matrix # Broadcasting adds arr to each row of matrix
9. Common Array Methods:
arr.shape
Size (number of elements):
arr.size
Sum of Array Elements:
arr.sum()
Mean and Standard Deviation:
arr.mean() # Mean
arr.std() # Standard deviation
10. Matrix Operations:
Dot Product (Matrix Multiplication):
matrix1 = np.array([[1, 2], [3, 4]])
matrix2 = np.array([[5, 6], [7, 8]])
result = np.dot(matrix1, matrix2) # Matrix multiplication
Transpose of a Matrix:
matrix.T
11. Random Number Generation:
random_arr = np.random.rand(3, 3) # 3x3 array of random floats between 0 and 1
Random Integers:
random_ints = np.random.randint(0, 10, size=(3, 3)) # Random integers from 0 to 9
12.Linear Algebra Functions:
inv_matrix = np.linalg.inv(matrix)
Eigenvalues and Eigenvectors:
eigvals, eigvecs = np.linalg.eig(matrix)
13. Array Manipulation:
stacked = np.vstack((arr1, arr2)) # Stack arrays vertically
stacked = np.hstack((arr1, arr2)) # Stack arrays horizontally
Splitting Arrays:
np.split(arr, 3) # Split into 3 parts
14. Advanced Functions:
np.concatenate((arr1, arr2), axis=0) # Concatenate along axis 0 (vertically)
Unique Elements in an Array:
np.unique(arr) # Find unique elements
Best Practices:
Excercise :
Here’s a list of popular Python libraries, categorized by their usage:
Data Manipulation and Analysis
2. Data Visualization
3. Machine Learning and AI
4. Data Science and Statistics
5. Web Development
6. Big Data and Databases
7. Natural Language Processing (NLP)
8. Image Processing and Computer Vision
9. Web Scraping
10. Network and API Interaction
11. Automation and Scripting
12. Testing
13. File Handling and PDF
14. Cybersecurity and Cryptography
15. DevOps and Cloud
16. Game Development
17. Audio and Video Processing
18. Data Encryption and Security
Actively available to join immediately Project Delivery & Operations 21+ years of remarkable success streamlining Process and delivering maximum outcomes through latest technology
4 天前Interesting
Tech Lead Full Stack .NET/Angular | ETLA (Don't follow :-)
1 周Bardzo pomocne