NumPy Arrays — Fundamentals
NumPy is the numerical backbone of Python data analytics. Pandas is built on top of it. Interviewers test NumPy to check if you understand vectorised operations — the key to fast data processing.
What is NumPy and why is it faster than Python lists?
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
arr * 2 # [2, 4, 6, 8, 10] — vectorised, no loop neededNumPy arrays store data in contiguous memory blocks and use C-level operations — no Python interpreter overhead per element. Operations on 1 million elements are 10-100x faster than a Python loop.
How do you create NumPy arrays?
np.array([1, 2, 3]) # from list
np.zeros((3, 4)) # 3x4 array of 0s
np.ones((2, 3)) # 2x3 array of 1s
np.arange(0, 10, 2) # [0, 2, 4, 6, 8]
np.linspace(0, 1, 5) # [0.0, 0.25, 0.5, 0.75, 1.0]
np.random.randint(0, 100, (3, 3)) # random 3x3arange() is like Python range() but returns an array. linspace() creates evenly spaced values — useful for generating axis labels, bins, or simulation inputs.
How do you perform basic array operations?
a = np.array([10, 20, 30])
b = np.array([1, 2, 3])
a + b # [11, 22, 33]
a - b # [9, 18, 27]
a * b # [10, 40, 90]
a / b # [10.0, 10.0, 10.0]
a ** 2 # [100, 400, 900]All arithmetic operations are element-wise and vectorised. No loops needed. This is how Pandas column arithmetic works internally.
What is array slicing and how do you index a 2D array?
arr = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
arr[0] # [1, 2, 3] — first row
arr[:, 1] # [2, 5, 8] — second column
arr[1, 2] # 6 — row 1, col 2
arr[0:2, 1:] # [[2,3],[5,6]]The syntax is arr[rows, cols]. This is exactly how Pandas .iloc[] works — it uses NumPy indexing underneath. Master this and .iloc[] becomes intuitive.
How do you compute basic statistics with NumPy?
arr = np.array([10, 20, 30, 40, 50])
np.mean(arr) # 30.0
np.median(arr) # 30.0
np.std(arr) # standard deviation
np.var(arr) # variance
np.sum(arr) # 150
np.min(arr) # 10
np.max(arr) # 50
np.percentile(arr, 75) # 40.0These are the building blocks of EDA. Pandas descriptive stats (.describe()) calls these NumPy functions internally. Knowing both layers helps you understand what .describe() actually computes.
EVIKA ACADEMY · PYTHON FOR DATA ANALYTICS
Want to master Python with live practice?
Join our Python for Data Analysis course — live classes in Noida and online across India.
Book Free Demo Class →