Lakshmi Prasad B.’s Post

🚀 Day 7 of #100DaysOfDataEngineering Topic: Python Advance - NumPy Basics Tags: #Python #NumPy #DataEngineering #DataScience Today marks the start of our journey into Python for numerical computing. Meet NumPy (Numerical Python), the core library that powers data transformations, mathematical operations, and many popular tools like Pandas and Scikit-learn. 💡 What is NumPy? NumPy provides multi-dimensional arrays (ndarray) and efficient functions to work with them. It is built for speed, allowing you to process large datasets much faster than standard Python lists. Install NumPy with: pip install numpy Import the library: import numpy as np 🧱 Creating Arrays You can create NumPy arrays directly from Python lists or nested lists: import numpy as np # 1D array arr1 = np.array([10, 20, 30]) # 2D array arr2 = np.array([[5, 10, 15], [20, 25, 30]]) print(arr1.shape) # (3,) print(arr2.shape) # (2, 3) print(arr1.dtype) # int64 ⚙️ Common Attributes AttributeDescriptionndarray.shapeDimensions of the array (rows, columns)ndarray.dtypeType of data stored (int, float, etc.)ndarray.ndimNumber of dimensionsndarray.reshape()Change array shape without changing data 📊 Built-in Methods NumPy includes several helpful functions for creating arrays quickly: # Evenly spaced values (like range) np.arange(0, 10, 2) # [0 2 4 6 8] # Arrays of zeros and ones np.zeros((2, 3)) # 2x3 array of zeros np.ones((3, 2)) # 3x2 array of ones # Equally spaced numbers np.linspace(0, 10, 5) # [0. 2.5 5. 7.5 10.] 🎲 Generating Random Numbers NumPy makes it simple to generate test data for experiments and simulations: # Random values (uniform distribution) np.random.rand(3, 4) # Random values (normal distribution) np.random.randn(2, 3) # Random integers between 4 and 40 np.random.randint(4, 40, 10) # 4x4 matrix of random integers up to 50 np.random.randint(50, size=(4,4)) ✅ Key Takeaway NumPy is all about speed and simplicity. It lets you handle large datasets and perform calculations efficiently. These array operations form the foundation of every scalable data pipeline.

To view or add a comment, sign in

Explore content categories