🐍 Python Advanced

What is NumPy in Python?

Why Interviewers Ask This

Senior Python engineers are expected to reason about architecture, performance, and edge cases. This question separates mid-level from senior candidates by testing deep system-level understanding.

Answer

NumPy is the fundamental package for scientific computing in Python, providing a powerful N-dimensional array object and vectorized mathematical operations. The core is the ndarray — a contiguous block of memory storing homogeneous data. Operations on arrays are vectorized (applied element-wise in C) — 10-100x faster than Python loops. Create: np.array([1, 2, 3]), np.zeros((3, 4)), np.ones(), np.arange(0, 10, 0.5), np.linspace(0, 1, 100). Operations: arr * 2, arr + arr, np.sqrt(arr). Indexing: arr[0, 1], slicing: arr[1:3, :], boolean indexing: arr[arr > 5]. Broadcasting: operations on different-shaped arrays. Reshape: arr.reshape(2, 3). Linear algebra: np.dot(), np.linalg.solve(). NumPy is the foundation of the Python data science stack (Pandas, SciPy, Matplotlib, scikit-learn).

Common Mistake

Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong Python candidates.