NumPy (Numerical Python) is the fundamental library for numerical and scientific computing in Python. It provides a fast, memory-efficient way to handle large datasets, perform mathematical operations, and work with multidimensional arrays.
Codeflare is one of the popular areas for tech training in Abuja. You can learn software development programs both online and onsite
Whether you’re doing data analysis, machine learning, image processing, or simulations—NumPy is the first tool you must learn.
NumPy is a Python library that supports:
If you don’t have NumPy installed:
pip install numpy Import it in your script:
import numpy as np The alias np is the global standard.
import numpy as np
arr = np.array([1, 2, 3, 4])
print(arr) matrix = np.array([[1, 2], [3, 4]]) np.zeros((3, 3)) # 3x3 matrix of zeros
np.ones((2, 4)) # 2x4 matrix of ones
np.arange(0, 10, 2) # array: [0 2 4 6 8]
np.linspace(1, 5, 4) # evenly spaced: [1. 2.33 3.66 5.] arr = np.array([[1, 2, 3], [4, 5, 6]])
arr.shape # (2, 3)
arr.ndim # 2
arr.size # 6
arr.dtype # int64 (or similar) Works like Python lists, but more powerful.
arr = np.array([10, 20, 30, 40, 50])
arr[0] # 10
arr[-1] # 50
arr[1:4] # [20 30 40] matrix = np.array([[10, 20, 30],
[40, 50, 60]])
matrix[0, 1] # 20
matrix[:, 2] # third column: [30 60] NumPy shines here—no loops needed.
arr = np.array([1, 2, 3, 4])
arr + 5 # [6 7 8 9]
arr * 2 # [2 4 6 8]
arr ** 2 # [1 4 9 16] Element-wise operations make NumPy extremely fast.
Built-in universal functions (ufuncs):
np.sqrt(arr)
np.log(arr)
np.sin(arr)
np.sum(arr)
np.mean(arr)
np.max(arr)
np.min(arr) arr = np.arange(12)
arr.reshape(3, 4) # 3 rows, 4 columns a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
np.vstack((a, b)) # vertical stack
np.hstack((a, b)) # horizontal stack np.split(np.arange(10), 2) np.random.rand(3, 3) # uniform distribution
np.random.randn(3, 3) # normal distribution
np.random.randint(0, 10, 5) # 5 integers between 0–9 NumPy is the backbone of scientific computing in Python. Its powerful array system, speed, and mathematical functions make it essential for data analysis, ML, AI, and numerical simulations. Once you master NumPy, advanced libraries like Pandas and TensorFlow become much easier to understand.
Latest tech news and coding tips.
1. What Is the Golden Ratio? The Golden Ratio, represented by the Greek letter φ (phi), is…
In CSS, combinators define relationships between selectors. Instead of selecting elements individually, combinators allow you to target elements based…
Below is a comprehensive, beginner-friendly, yet deeply detailed guide to Boolean Algebra, complete with definitions, laws,…
Debugging your own code is hard enough — debugging someone else’s code is a whole…
Git is a free, open-source distributed version control system created by Linus Torvalds.It helps developers: Learn how to…
Bubble Sort is one of the simplest sorting algorithms in computer science. Although it’s not…